我正在尝试在CentOS 8上配置NGINX(使用SSL(。我相信我已经正确配置了它,但我无法摆脱NGINX欢迎页面。我尝试了很多方法,甚至删除了整个/usr/share/nginx/html
目录,但我仍然在example.com
上受到NGINX的欢迎,而example.com/index.html
给了我网站的索引页。事实上,我已经注意到,我在下面实现的http到https和非www到www重定向在example.com
上不起作用,但在example.com/index.html
上起作用。我的网站的根目录是/var/www/example.com/html
。下面给出的配置文件称为example.com.conf
,位于/etc/nginx/conf.d/
。
server {
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
listen [::]:443 ssl ipv6only=on default_server; # managed by Certbot
listen 443 ssl default_server; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
# Redirect non-SSL to SSL
server {
listen 80;
listen [::]:80;
server_name .example.com;
return 301 https://$host$request_uri;
}
# Redirect non-www to www
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
因此,您似乎需要使用sudo nano /etc/nginx/nginx.conf
编辑全局配置文件并注释掉"default_server;在听力陈述中。或者,删除全局conf文件中的整个服务器块也可以,只要保留读取example.com.conf文件的include语句即可。
include /etc/nginx/conf.d/*.conf;
server {
listen 80; # default_server;
listen [::]:80; # default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}