Nginx配置文件
-
加载配置文件
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -
测试配置文件
-
重启Nginx
sudo /usr/local/nginx/sbin/nginx -s reload -
配置文件
1 user nginx; # Nginx 的启动用户 2 worker_processes 2; # Nginx 的工作进程数量,与 CPU 核心数保持一致 3 worker_cpu_affinity 01 10; # 将每一个工作进程与对应的CPU绑定, 能减少进程上下文切换时的时间消耗 4 pid /var/run/nginx.pid; # 进程的 PID 文件 5 error_log /var/log/nginx/error.log warn; # 错误日志 6 7 events { 8 use epoll; # 使用 epoll 多路复用 9 worker_connections 1024; # 单个工作进程的最大连接数,可以设置为 65535 10 } 11 12 13 http { 14 include /etc/nginx/mime.types; 15 default_type application/octet-stream; 16 17 # 请求日志的格式 18 log_format main '$time_local $remote_addr $remote_user $status ' 19 '$request_time $request [$body_bytes_sent/$bytes_sent] ' 20 '"$http_user_agent" "$http_referer" "$http_x_forwarded_for"'; 21 22 access_log /var/log/nginx/access.log main; # 请求日志的路径 23 24 # 跟性能相关的参数 25 sendfile on; 26 tcp_nopush on; # 能让数据传输的更快 27 keepalive_timeout 65; # 启用 KeepAlive 功能 28 gzip on; # 启用 HTTP 报文压缩 29 30 # 负载均衡设置 31 upstream app_server { 32 server 127.0.0.1:8000 weight=3; 33 server 127.0.0.1:9000 weight=6; 34 } 35 36 # 服务器设置 37 server { 38 listen 80; # 端口 39 server_name swiper.seamile.cn; # 域名 40 41 # 当前服务器日志设置 42 access_log /opt/swiper/logs/ngx_access.log main; 43 error_log /opt/swiper/logs/ngx_error.log; 44 45 # 网站图标设置 46 location = /favicon.ico { 47 empty_gif; 48 access_log off; 49 } 50 51 # 静态文件设置 52 location /statics/ { 53 root /opt/swiper/; 54 expires 30d; 55 access_log off; 56 } 57 58 # Gunicorn 设置 59 location /api/ { 60 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 添加代理跳转的header 61 proxy_set_header Host $http_host; # 把主机原来的header写进去。上下这两句修正被nginx代理后的http请求的header 62 proxy_redirect off; #把跳转相关的东西关掉 63 proxy_pass http://app_server; # 将请求转发给负载均衡器 64 } 65 } 66 }
