nginx配置事例

#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


#非http请求配置
stream {
    #资源数据库
 		server {
        listen 3308;
				tcp_nodelay on;
				proxy_responses 1;
        proxy_connect_timeout 30s;
        proxy_timeout 30s;
        proxy_pass 192.168.0.2:3306;
    }
    #开发数据库
 		server {
        listen 3307;
				tcp_nodelay on;
				proxy_responses 1;
        proxy_connect_timeout 30s;
        proxy_timeout 30s;
        proxy_pass 192.168.0.6:3306;
    }
    #MongoDB
 		server {
        listen 27017;
				tcp_nodelay on;
				proxy_responses 1;
        proxy_connect_timeout 30s;
        proxy_timeout 30s;
        proxy_pass 192.168.0.6:27017;
    }
	#redis
	server {
        listen 6380;
				tcp_nodelay on;
				proxy_responses 1;
        proxy_connect_timeout 30s;
        proxy_timeout 30s;
        proxy_pass 192.168.0.6:6379;
    }
}





#http请求配置
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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0
   #这个参数表示http连接超时时间,默认是65s。要是上传文件比较大,在规定时间内没有上传完成,就会自动断开连接!所以适当调大这个时间。
    keepalive_timeout  100;
    
     gzip off;
    #gzip  on;
    #gzip_min_length 1k;
    #gzip_buffers 4 16k;
    #gzip_comp_level 4;
    #gzip_types text/css text/xml application/javascript;
    #gzip_vary on;
   
     client_header_timeout 120s;        #调大点
    client_body_timeout 120s;          #调大点
    client_max_body_size 100m;         #主要是这个参数,限制了上传文件大大小
 
    
    ###########################端口80配置#####################################
    server {
        listen       80;
        server_name  180.76.162.179;
        
        #农业调查图形化
        location /nysurvey/{
           root   /usr/local/nginx/html;
        }
				#创业企业调查图形化
        location /survey/{
            proxy_pass http://192.168.0.5:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

        }
	      #视频分析demo
	      location /videoAnalysis/{
            proxy_pass http://192.168.0.5:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

        }
			  #舆情demo
	      location /yuqing/{
            proxy_pass http://192.168.0.5:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

        }
	# 智能写作demo 
   	location /aiwritting/{
            proxy_pass http://192.168.0.5:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

        }


        #媒体云cms
        location /media_cms/ {
            proxy_pass http://192.168.0.5:8081;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        
        #媒体云user
        location /media_user/ {
            proxy_pass http://192.168.0.5:8083;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        #媒体云topic
        location /media_topic/ {
            proxy_pass http://192.168.0.5:8084;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        #媒体云sso
        location /sso/ {
            proxy_pass http://192.168.0.5:8082;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        #媒体云daily
        location /daily/ {
            proxy_pass http://192.168.0.5:8086;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        #媒体云analysis
        location /analysis/ {
            proxy_pass http://192.168.0.5:8087;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
        #媒体云analysis_file
        location /analysis_file/ {
            proxy_pass http://192.168.0.5:8089;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
				#媒体云aimedia_server
				location /aimedia_server/ {
            proxy_pass http://192.168.0.5:8088;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }
				#aidemo
				location /aidemo/ {
            proxy_pass http://192.168.0.5:8088;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
	  			# proxy_buffers         4 32k;
          # proxy_temp_file_write_size 64k;
        }
	#智能媒资库前置测试项目	
        location  /standard/{
	    proxy_pass http://192.168.0.5:8088;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
				
	}	
	#财富三期的接口				
	location /edwFront/{
            proxy_pass http://192.168.0.6:8080/edwFront/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

        }
	#公司门户网站首页
	location  /{
            proxy_pass http://192.168.0.5:8088/tjzm_corp/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

       } 


          #百度云nexus3
          location  /nexus/{
                  proxy_pass http://192.168.0.2:8081/nexus/;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-For $remote_addr;
                  proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
                  proxy_set_header Host $host;
          }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
   
		###########################端口8090配置#####################################
    server {
        listen       8090;
       # listen      somename:8080;
        server_name  180.76.162.179;

        location / {
            # proxy_redirect off;
            # 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_pass http://192.168.0.2:8090;
             proxy_connect_timeout 1;
             proxy_send_timeout 30;
             proxy_read_timeout 60;

        }

				#crapapi接口
				location /crapapi {
             proxy_pass http://192.168.0.2:8080/crapapi;
             proxy_connect_timeout 1;
             proxy_send_timeout 30;
             proxy_read_timeout 60;
        }
    }


  
    ###########################端口8081配置#####################################
   # server {
    #    listen       8081;
       # listen      somename:8080;
     #   server_name  180.76.162.179;
         #百度云nexus3
    #	location  /{
    #        proxy_pass http://192.168.0.2:8081/;
    #        proxy_set_header X-Real-IP $remote_addr;
    #        proxy_set_header X-Forwarded-For $remote_addr;
    #        proxy_set_header WL-Proxy-Client-IP $proxy_add_x_forwarded_for;
    #        proxy_set_header Host $host;
    #    }
    # }                                                                    


    ###########################端口81配置##################################### 
    server {
    	listen       81;
    	server_name  180.76.162.179;
      client_max_body_size 1024M;
      
      #svn配置
    	location /svn {
        	proxy_pass  http://192.168.0.2:81;
    	}	
    	location / {
        	return 404;
	    }
		}



    # HTTPS server
    #
    server {
     #   listen        80;
	listen       443 ssl;
        server_name  www.teejo.com.cn;

        ssl_certificate      /usr/local/nginx/ssl/teejo.com.cn.crt;
        ssl_certificate_key  /usr/local/nginx/ssl/teejo.com.cn.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

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

	#微信小程序验证文件  add by jiangyx 2018-03-28  
	location /OS1vOzd93S.txt{
		root	/usr/local/nginx/html/weixin/;
	}
	
	  location /favicon.ico{
                root    /usr/local/nginx/html/weixin/;
        }
	
	#location /*.(txt|ico)$ {
        #        root    /usr/local/nginx/html/weixin/;
        #}
		       
	# https 访问
        location / {
            #root  html;
           # index  index.html index.htm;
            proxy_redirect off;
     	    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_pass http://192.168.0.5/;
        }
    }

}
原文地址:https://www.cnblogs.com/yinz/p/9340148.html