nginx配置https同时http请求转发到https上

#user  nobody;
worker_processes  1;

#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;


    sendfile        on;

    keepalive_timeout  65;
    gzip  on;
    upstream www.yuyufeng.top {  
        server 127.0.0.1:8180;  
        #server 127.0.0.1:8280;  
    }

     server {
        listen 443 default ssl;  
        server_name  www.yuyufeng.top;

        #ssl on;  
        ssl_certificate      /usr/local/nginx/cert/214319706960205.pem;
        ssl_certificate_key  /usr/local/nginx/cert/214319706960205.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

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

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://www.yuyufeng.top;
            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;
        }


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

    }

    server {
        listen       80;
        server_name  www.yuyufeng.top;
        rewrite ^(.*)$ https://www.yuyufeng.top permanent;
        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://www.yuyufeng.top;
            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;
        }


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

    }



}
发布了155 篇原创文章 · 获赞 147 · 访问量 36万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览