nginx 多个80端口转发

  1. #user  nobody;  
  2. worker_processes  2;  
  3. worker_rlimit_nofile 50000;  
  4. worker_cpu_affinity 00000001  10000000;  
  5. #error_log  logs/error.log;  
  6. #error_log  logs/error.log  notice;  
  7. #error_log  logs/error.log  info;  
  8.   
  9.   
  10. #pid        logs/nginx.pid;  
  11.   
  12.   
  13. #服务器最大支持257134    ulimit -u  
  14. events {  
  15.     worker_connections  50000;  
  16. }  
  17.   
  18.   
  19.   
  20.   
  21. http {  
  22.     include       mime.types;  
  23.     default_type  application/octet-stream;  
  24.     server_names_hash_bucket_size 64;  
  25.     #log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘  
  26.     #                  ‘$status $body_bytes_sent “$http_referer” ‘  
  27.     #                  ‘”$http_user_agent” “$http_x_forwarded_for”‘;  
  28.   
  29.   
  30.     #access_log  logs/access.log  main;  
  31.       
  32.     sendfile        on;  
  33.     #tcp_nopush     on;  
  34.       
  35.     #keepalive_timeout  0;  
  36.     keepalive_timeout  65;  
  37.     #压缩处理  
  38.     gzip  on;  
  39.     gzip_min_length 1k;  
  40.     #16倍申请内存  
  41.     gzip_buffers 16 64k;  
  42.     #gzip压缩版本  
  43.     gzip_http_version 1.1;  
  44.     gzip_comp_level 2;#gzip压缩比,1压缩比最小处理速度最快   1~9  
  45.     gzip_types text/plain application/x-javascript text/css text/javascript application/javascript;  
  46.     gzip_vary on;  
  47.     #不支持1~6 IE  
  48.     gzip_disable “MSIE [1-6]\.”;  
  49.   
  50.   
  51.     #负载均衡  
  52.      upstream bakend {  
  53.          ip_hash;  
  54.          server 127.0.0.1:9080;  
  55.          server 127.0.0.1:9180;  
  56.     }  
  57.    
  58.    #www  
  59.     server {  
  60.         listen       8090;  
  61.         server_name  127.0.0.1;  
  62.         location / {  
  63.             root   html;  
  64.             index  index.html index.htm;  
  65.         }  
  66.   
  67.   
  68.        
  69.         error_page   404 500 502 503 504  /50x.html;  
  70.         location = /50x.html {  
  71.             root   html;  
  72.         }  
  73.   
  74.   
  75.     }  
  76.   
  77.   
  78.   
  79.   
  80.   #物流www  
  81.     server {  
  82.         listen       80;  
  83.         server_name  www.****.com ;  
  84.         location / {  
  85.           proxy_pass   http://127.0.0.1:8090;  
  86.       proxy_set_header   Host    $host;  
  87.           proxy_set_header   Remote_Addr    $remote_addr;  
  88.           proxy_set_header   X-Real-IP    $remote_addr;  
  89.           proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;  
  90.         }  
  91.   
  92.   
  93.     error_page   404 500 502 503 504  /50x.html;  
  94.         location = /50x.html {  
  95.             root   html;  
  96.         }  
  97.     }  
  98.       
  99.   #物流APP  
  100.     server {  
  101.         listen       80;  
  102.         server_name  lgs.****.com ;  
  103.         location / {  
  104.           proxy_pass  http://127.0.0.1:9880;  
  105.       proxy_set_header   Host    $host;  
  106.           proxy_set_header   Remote_Addr    $remote_addr;  
  107.           proxy_set_header   X-Real-IP    $remote_addr;  
  108.           proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;  
  109.         }  
  110.   
  111.   
  112.     error_page   404 500 502 503 504  /50x.html;  
  113.         location = /50x.html {  
  114.             root   html;  
  115.         }  
  116.     }  
  117.   #电商APP  
  118.     server {  
  119.         listen       80;  
  120.         server_name  emall.****.com;  
  121.         location / {  
  122.            #proxy_pass   http://127.0.0.1:9080;  
  123.       proxy_pass http://bakend/;  
  124.           proxy_set_header   Host    $host;  
  125.           proxy_set_header   Remote_Addr    $remote_addr;  
  126.           proxy_set_header   X-Real-IP    $remote_addr;  
  127.           proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;  
  128.         }  
  129.   
  130.   
  131.     error_page   404 500 502 503 504  /50x.html;  
  132.         location = /50x.html {  
  133.             root   html;  
  134.         }  
  135.     }  
  136.       
  137.   #物流后台  
  138.    server {  
  139.         listen       80;  
  140.         server_name  managelgs.****.com;  
  141.         location / {  
  142.           proxy_pass   http://127.0.0.1:9780;  
  143.       proxy_set_header   Host    $host;  
  144.           proxy_set_header   Remote_Addr    $remote_addr;  
  145.           proxy_set_header   X-Real-IP    $remote_addr;  
  146.           proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;  
  147.         }  
  148.   
  149.   
  150.     error_page   404 500 502 503 504  /50x.html;  
  151.         location = /50x.html {  
  152.             root   html;  
  153.         }  
  154.     }  
  155.   
  156.   
  157.    #电商后台  
  158.     server {  
  159.         listen       80;  
  160.         server_name  manage.****.com;  
  161.         location / {  
  162.            proxy_pass   http://127.0.0.1:9280;  
  163.        proxy_set_header   Host    $host;  
  164.            proxy_set_header   Remote_Addr    $remote_addr;  
  165.            proxy_set_header   X-Real-IP    $remote_addr;  
  166.            proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;  
  167.         }  
  168.   
  169.   
  170.     error_page   404 500 502 503 504  /50x.html;  
  171.         location = /50x.html {  
  172.             root   html;  
  173.         }  
  174.     }  
  175.       
  176.    #电商以及物流图片  
  177.     server {  
  178.         listen       80;  
  179.         server_name  images.****.com;  
  180.         location / {  
  181.            proxy_pass   http://127.0.0.1:1314;  
  182.           proxy_max_temp_file_size 0;  
  183.           expires 1h;  
  184.             
  185.          }  
  186.   
  187.   
  188.     error_page   404 500 502 503 504  /50x.html;  
  189.         location = /50x.html {  
  190.             root   html;  
  191.         }  
  192.     }  
  193.   
  194.   
  195.     # another virtual host using mix of IP-, name-, and port-based configuration  
  196.     #  
  197.     #server {  
  198.     #    listen       8000;  
  199.     #    listen       somename:8080;  
  200.     #    server_name  somename  alias  another.alias;  
  201.   
  202.   
  203.     #    location / {  
  204.     #        root   html;  
  205.     #        index  index.html index.htm;  
  206.     #    }  
  207.     #}  
  208.   
  209.   
  210.   
  211.   
  212.     # HTTPS server  
  213.     #  
  214.     #server {  
  215.     #    listen       443;  
  216.     #    server_name  localhost;  
  217.   
  218.   
  219.     #    ssl                  on;  
  220.     #    ssl_certificate      cert.pem;  
  221.     #    ssl_certificate_key  cert.key;  
  222.   
  223.   
  224.     #    ssl_session_timeout  5m;  
  225.   
  226.   
  227.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;  
  228.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  
  229.     #    ssl_prefer_server_ciphers   on;  
  230.   
  231.   
  232.     #    location / {  
  233.     #        root   html;  
  234.     #        index  index.html index.htm;  
  235.     #    }  
  236.     #}  
  237.   
  238.   
  239. }