【发布时间】:2018-02-12 12:39:45
【问题描述】:
我有几个网站配置了 Nginx (nginx/1.10.3 (Ubuntu)) 服务器块。浏览到下面列出的任何已配置域都会按预期工作:
那些被配置为使用 HTTPS 的会自动获得 HTTP -> HTTPS 重定向(例如 morgrowe.com)。问题是当我浏览到不存在的子域时(例如:dosnotexist.morgrowe.com)。如果我访问 http://doesnotexist.morgrowe.com,我会被重定向到默认的 Nginx 页面(这是我想要的)。但是,如果我访问 https://doesnotexist.morgrowe.com,我会被重定向到 https://api.morgrowe.com。
这还不错,但如果我转到https://doesnotexist.carpyslocksmiths.com,我也会被重定向到https://api.morgrowe.com。
在哪里可以找到实现这一点的配置?理想情况下,我希望默认的 nginx 404 页面看起来像 http 连接那样。我想我必须在/etc/nginx/sites-available/default 中配置一些东西,但我不知道从哪里开始。这是我的/etc/nginx/sites-available/default 文件内容:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
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;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
【问题讨论】: