所以我有这个 NGINX 组态档:
events { }
http {
server {
listen 443 ssl;
ssl_certificate /home/dietpi/certs/cert.pem;
ssl_certificate_key /home/dietpi/certs/privkey.pem.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
它是 Docker 容器的反向代理。它为我做 SSL。我想将 HTTP 重定向到 HTTPS,所以我尝试添加以下内容:
events { }
http {
server {
listen 80 default_server;
server _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /home/dietpi/certs/cert.pem;
ssl_certificate_key /home/dietpi/certs/privkey.pem.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
但现在它不起作用(sudo nginx -t
失败)。它是这样说的:
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
大多数遇到此错误的人往往http
会将服务器块放在一个块中,而将其放在一个块中可以修复它。但是……我的server
街区已经在http
街区中了。那么我该如何解决呢?
uj5u.com热心网友回复:
错别字server
而不是server_name
在server {}
块内
server {
listen 80 default_server;
server_name _; # ? corrected
}
0 评论