首页 > 系统相关 >【笔记】nginx配置

【笔记】nginx配置

时间:2023-03-09 13:11:06浏览次数:64  
标签:http 配置 笔记 nginx usr gzip fastcgi size

一、创建Nginx运行使用的用户

1.1创建system用户组

/usr/sbin/groupadd system

1.2创建用户nginx

/usr/sbin/useradd -g system nginx

1.3查看默认配置文件

cat /usr/local/webserver/nginx/conf/nginx.conf
image

二、配置文件

2.1 修改配置文件
详细配置
user nobody;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
  include mime.types;
  default_type application/octet-stream;
  log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';
  
#charset gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
 
  #limit_zone crawler $binary_remote_addr 10m;
 #下面是server虚拟主机的配置
  upstream halo {
	server 127.0.0.1:8090;
	}
  server {
	listen 80;
	listen [::]:80;
	server_name www.xiangliheart.com;
	client_max_body_size 1024m;
	location / {
		proxy_pass http://halo;
		proxy_set_header HOST $host;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		}
	}
}
2.2 检查配置文件nginx.conf的正确性

/usr/local/webserver/nginx/sbin/nginx -t
image

三、启动 Nginx

/usr/local/webserver/nginx/sbin/nginx
image

四、访问站点,验证反向代理正常

访问代理前地址:http://www.xiangliheart.com:8090/
image

访问代理后地址:http://www.xiangliheart.com
image

标签:http,配置,笔记,nginx,usr,gzip,fastcgi,size
From: https://www.cnblogs.com/xiangliheart/p/17195722.html

相关文章

  • 前端从0-1使用nginx打包部署静态资源,以及hash和history配置汇总
    第一:我们要搭建nginx部署基础环境具体流程可参考这个链接从0-1超详细教你实现前端代码nginx部署全流程第二:我们要知道前端路由hash和history实现以及区别路由功能:1、记......
  • Nginx反向代理-Keepalived做高可用
    Keepalived-HA-主节点配置管理1.软件安装[root@ha1nginx]#yuminstall-ykeepalived[root@ha1nginx]#cd/etc/keepalived/[root@ha1keepalived]#mvkeepalived.conf......
  • Nginx 高可用方案
    准备工作192.168.16.128192.168.16.129两台虚拟机。安装好Nginx安装Nginx更新yum源文件:rpm-ivhhttp://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-......
  • 【WinForm】 自学笔记一:项目创建以及基本操作
    这两年C#客户端开发比较火,有很多WinForm以及WPF的开发需求。为了跟上时代发展的步伐,开始学习相关的知识。笔记内容以个人实际学习情况为主,记录基本情况,可能不够详细......
  • npm 基础使用配置淘宝镜像
    查看npm配置文件npmconfiglist配置npm使用淘宝镜像npmconfigsetregistryhttp://registry.npm.taobao.org/安装依赖npminstall注意大家如果np......
  • R语言学习笔记二
    ggplot2cookbook可视化工具htmlwidgets地图leaflet时间序列dygraph网络networkD3带R接口的javascript可视化工具包plotly所有图形工具的完整列表#接下来所使用......
  • 数据源配置
    spring:#数据源配置datasource:type:com.alibaba.druid.pool.DruidDataSourcedriver-class-name:com.mysql.cj.jdbc.Driverurl:jdbc:mysql://127.0.0.......
  • 随堂笔记14-spring之事务
    @EnableTransactionManagement工作原理:开启事务本质就是增加一个advisor,而使用@EnableTranscationManagement是向spring容器内添加俩个beanautoproxyRegisterproxyT......
  • 随堂笔记13-spring之aop底层源码
    动态代理:代理模式:为其他对象提供一种代理来控制对这个对象的访问,增强一个类中的某个方法,对其进行扩展调用分为俩类,一类是jdk的接口代理,需要有接口,另一种是cglib代......
  • gitlab 配置 ssh keys
    gitlab 配置sshkeys1、生成id_rsa.pubssh-keygen-trsa-C‘email’ 2、.ssh文件夹目录在c:\users\用户名\下,找到id_rsa.pub文件并复制里面的内容  3......