![NGINX 中的 http 到 https 重定向](https://linux22.com/image/1602555/NGINX%20%E4%B8%AD%E7%9A%84%20http%20%E5%88%B0%20https%20%E9%87%8D%E5%AE%9A%E5%90%91.png)
我有一个使用 http 协议的网站,现在我想将其更改为 https,但我不知道如何更改我的默认文件。这是我的默认内容:
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
您知道我应该在代码中添加什么吗?
答案1
根据您的原始问题和 Nginx 的默认配置文件:
# HTTPS server
server {
listen 443 ssl;
# server_name localhost;
# Lacking a path, defaults to searching the .conf folder
ssl_certificate your.ssl.crt;
ssl_certificate_key your.ssl.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}