Nginx 强制 HTTPS 配置

2020-08-27 16:50:25 浏览数 (1)

Nginx 强制 HTTPS 配置

代码语言:javascript复制
server {
            listen 443 ssl;
            server_name example.com;
            ssl_certificate     /cert/example.com.pem;
            ssl_certificate_key /cert/example.com.key;

            access_log  off;
            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://localhost:5000;
            }
}

server {
            listen 80;
            server_name example.com;
            return 301 https://$server_name$request_uri;
}

注意:需要将 server_name、proxy_pass、ssl_certificate、ssl_certificate_key 改为自己的值。

0 人点赞