我的 ssl 文件位于 nginx /etc/nginx/ssl/default 下
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
listen [::]:443;
server_name domain.com;
ssl_certificate /etc/nginx/ssl/domain.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/perm_with_key.pem;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 400000;
proxy_send_timeout 400000;
proxy_read_timeout 400000;
send_timeout 400000;
proxy_hide_header X-Frame-Options;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
}
}
我不知道我在这里错过了什么。我从 godaddy 获得了 ssl 证书。
有人能给我解决方案吗?谢谢。
答案1
您需要为 80 和 443 设置单独的服务器块:
server {
listen 80 default_server;
server_name _;
access_log off;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
server_name domain.com _;
<Put the rest of your existing stuff here with only one server_name directive>
}
这会将所有内容重定向到 80 到 443
Nginx 有很好的文档。请收藏: