nginx默认配置

Posted welkinok

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx默认配置相关的知识,希望对你有一定的参考价值。

user  nobody;
worker_processes 2;
worker_cpu_affinity 000000001000 000000010000; 
worker_rlimit_nofile 51200;
pid  sbin/nginx.pid;
error_log  logs/error.log  error;

events {
  use epoll;
  worker_connections 1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  server_tokens off;
  keepalive_timeout  75s;

  sendfile off;
  tcp_nopush on;
  tcp_nodelay on;

  client_max_body_size 32m;

  # Proxy
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header REMOTE-HOST $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_redirect off;
  proxy_pass_header Set-Cookie;
  proxy_hide_header X-Powered-By;
  proxy_hide_header X-Mod-Pagespeed;
  proxy_ignore_client_abort off;
  proxy_cache_valid any 10m;

  proxy_connect_timeout    75s;
  proxy_read_timeout       75s;
  proxy_send_timeout       75s;


  # Log
  log_format  main ‘-[$time_local] <$remote_addr> <$request -$status>  <$upstream_addr -$upstream_status>‘;
  access_log  logs/access.log  main buffer=16k;
  open_log_file_cache max=10 inactive=30s min_uses=2 valid=60s;

  # LoadBlance
  upstream appservers {
    server 192.168.240.1:8081 weight=5 max_fails=2 fail_timeout=30s;
    server 192.168.240.1:8082 weight=4 max_fails=2 fail_timeout=30s;
    #server 192.168.240.1:8083 weight=3 max_fails=2 fail_timeout=30s;
    #server 192.168.240.1:8084 weight=2 max_fails=2 fail_timeout=30s;
    server 192.168.240.1:8085 backup;
    #server 192.168.240.2:8081 weight=5 max_fails=2 fail_timeout=30s;
    #server 192.168.240.2:8082 weight=4 max_fails=2 fail_timeout=30s;
    #server 192.168.240.2:8083 weight=3 max_fails=2 fail_timeout=30s;
    #server 192.168.240.2:8084 weight=2 max_fails=2 fail_timeout=30s;
    #server 192.168.240.2:8085 backup;
    #server 192.168.240.1:8081;
    #server 192.168.240.1:8082;
    #server 192.168.240.1:8083;
    #server 192.168.240.1:8084;
    #server 192.168.240.1:8085;
    #server 192.168.240.2:8081;
    #server 192.168.240.2:8082;
    #server 192.168.240.2:8083;
    #server 192.168.240.2:8084;
    #server 192.168.240.2:8085;
}

 upstream moonregionservers {
    server 192.168.240.10:8081;
    server 192.168.240.10:8082;
    server 192.168.240.10:8083;
    server 192.168.240.10:8084;
    server 192.168.240.10:8085;
}

 upstream moonMallproxyserver {
    server 127.0.0.1:8081;
    #server 127.0.0.1:8082;
    server 192.168.236.3:8081;
    #server 192.168.236.3:8082;
    #server 192.168.236.3:8083;
    #server 192.168.236.3:8084;
    #server 192.168.236.3:8085;
}

 upstream bluemmSiteserver {
    server 192.168.240.2:8085;
    #server 127.0.0.1:8082;
}

upstream bluemoonProxy{
	server 127.0.0.1:8083;
}



  server {
       server_name mall.bluemoon.com.cn;
       listen 80;
       #charset utf-8;

       location /nginx_status {
         stub_status on;
         access_log off;
       } 

       location / {
         proxy_pass http://appservers;
         proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        }

        # FTP.
        #location ^~/ftp {
        # proxy_pass http://10.251.68.12/;
        #}

	location /wxPay/ {
           proxy_pass https://api.mch.weixin.qq.com:443/pay/unifiedorder;
	   proxy_redirect default ;
        }
	
	 location /moonRegion {
           index index.html index.htm;
           proxy_pass http://moonregionservers;
        }
	
	 location /App {
 	   alias /data/static/App;
           index index.html index.htm;
        }

	 location /webApp {
	   alias /data/static/webApp;
           index index.html index.htm;
        }
	
	location /mall {
           alias /data/static/mall;
           index index.html index.htm;
        }

	location /upload {
           proxy_pass http://192.168.240.3:80/upload/;
        }

	location /angelUpload{
	  proxy_pass http://192.168.240.22:80/upload/;
	}

	#wx pay
	#wx pay
	location /moonMall-proxy {
          #proxy_pass http://192.168.236.2:8081/moonMall-proxy;
          proxy_pass http://moonMallproxyserver;
        }
	
	#bluemmSite
	location /bluemmSite {
          #proxy_pass http://192.168.236.2:8081/moonMall-proxy;
          proxy_pass http://bluemmSiteserver;
        }

        #kouzhiqiang webservice proxy
        location /bluemoon-proxy {
          proxy_pass http://bluemoonProxy;
        } 

        # Global.
        location = / {
                root   html;
                index  index.html index.htm;
        }

        location = /update.html {
                root   html;
        }

        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
                root   html;
        }

        error_page 403 404 410    /404.html;
        location = /404.html {
                root   html;
        }
    }



     #ssl
	
	#upstream wxpay {
    	#	server https://api.mch.weixin.qq.com;	
 
	#}
    server {
        listen       443 ssl;
        server_name  s.bluemoon.com.cn;

        ssl_certificate      /data/key/moonmall.bluemoon.com.cn_bundle.crt;
        ssl_certificate_key  /data/key/moonmall.bluemoon.com.cn.key;

        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        keepalive_timeout 70;

        location / {
            #proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto  $scheme;
            proxy_pass https://api.mch.weixin.qq.com/pay/unifiedorder;
	    #proxy_pass http://192.168.240.10:8080/moonRegion/;	

        }

	
        #location /wxPay {
         #  proxy_pass https://api.mch.weixin.qq.com:443/pay/unifiedorder;
       # }
}
}

 

以上是关于nginx默认配置的主要内容,如果未能解决你的问题,请参考以下文章

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

Nginx配置文件详细介绍

Nginx 跨域

php网站修改默认访问文件的nginx配置

Prometheus配置文件

Nginx——Nginx的默认配置语法(Centos7通过yum方式安装)