我将只在我的子域上提供一个 webapp,admininstration.example.com
但它也可以从 example.com 访问。这是我的 nginx 配置:
http {
server {
server_name = _;
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
server_name = example.com;
listen 80;
location / {
return 404;
}
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name administration.example.com;
ssl_certificate /etc/nginx/certificate.cer;
ssl_certificate_key /etc/nginx/ppk2.key;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location /pgadmin4/ {
proxy_set_header X-Script-Name /pgadmin4;
proxy_set_header X-Scheme $scheme;
proxy_set_header Host $host;
proxy_pass http://localhost:5050/;
proxy_redirect off;
}
}
}
知道配置的哪一部分是错误的吗?
答案1
server{}
您的 HTTPS 端口 443 上只有一个。
这location / { return 404; }
仅适用于端口 80 上的纯 HTTP。例如,您可以
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/certificate.cer;
ssl_certificate_key /etc/nginx/ppk2.key;
location / {
return 404;
}
}
=
顺便说一句,语法中没有server_name
。