Neurohazard
暮雲煙月,皓首窮經;森羅萬象,如是我聞。

Nginx 部署 HTTPS 网站示例文件

wpadmin~October 17, 2019 /System Management

Nginx 部署 HTTPS 网站示例文件

HTTPS 网站 示例

使用 /usr/sbin/nginx -t 检查配置文件是否有语法错误。
手动运行 /usr/sbin/nginx -c /etc/nginx/nginx.conf

以 hackmd 为例,假设运行在 http://127.0.0.1:3000 的位置。

server {
    listen 80;
    server_name hackmd.blkstone.me;

    return 301 https://$host$request_uri;
}

server {
    listen       443 ssl http2;
    listen       [::]:443 ssl;
    server_name  hackmd.blkstone.me;

    ssl_certificate server.crt;
    ssl_certificate_key server.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_pass http://127.0.0.1:3000;

        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *