Nginx实现静态服务器+https+负载均衡

#user  nobody;
# 进程数=CPU总核数
worker_processes  2;

#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 {
    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;
    keepalive_timeout  65;

    #gzip  on;

    # 反向代理
    upstream backend.com {
        server webappIp1:prot weight=1;
        server webappIp2:prot weight=2;
    }

    server {
        listen       80;
        server_name  www.guotanghang.com;
        
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        return      301 https://$server_name$request_uri;

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

    server {
        listen       443 ssl;
        server_name  www.yoursite.com;
        #ssl on;

        ssl_certificate      cert/yourCert.pem;
        ssl_certificate_key  cert/yourCert.key;

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

        #ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers  on;

        location / {
            root   E:\\webapp\\demo;
            index  index.html index.htm;

            proxy_hide_header Vary;
            proxy_hide_header X-Powered-By;

            proxy_set_header Host            $host;
            proxy_set_header X-Real_IP       $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        # 负载均衡路由
        location /war_name {
            proxy_pass http://backend.com;
            proxy_redirect default;
        }
    }

}
    

 

posted @ 2017-08-01 09:25  iFindU_San  阅读(415)  评论(0编辑  收藏  举报