当在配置中找不到时,Nginx 重定向到第一个按字母顺序排列的站点
我有几个网站,当我输入不存在的子域时,Nginx 会重定向到 /etc/nginx/sites-enabled 中的第一个可用网站。我的网站配置如下:
server {
listen 80;
listen [::]:80;
server_name *.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/app_name/build;
index index.html index.htm;
location / {
try_files $uri /index.html =404;
}
}
I have a few websites, and when I type in a subdomain that does not exist, Nginx redirects to the first available website in /etc/nginx/sites-enabled. My config is as follows for the websites:
server {
listen 80;
listen [::]:80;
server_name *.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/app_name/build;
index index.html index.htm;
location / {
try_files $uri /index.html =404;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完美,Ivan Shatsky 关于 default_server 的评论修复了它。但是我遇到了错误
duplicate default_server error
,我用以下方法修复了该错误:Perfect, Ivan Shatsky's comment about default_server fixed it. However I had an error
duplicate default_server error
, which I fixed with the following: