这是我的 nginx 配置,当我进入服务器时,curl localhost
我只看到默认的 nginx 页面。我在端口 80 上有一个“/”的服务器块,但它被忽略了。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
# expose /nginx_status but on a different port to avoid
# external visibility / conflicts with the app.
listen 8090;
listen [::]:8090;
location / {
root /dev/null;
}
location /nginx_status {
stub_status on;
access_log off;
}
}
server {
listen 80;
listen [::]:80;
location / {
root /var/http/test.html;
index test.html;
}
}
}
答案1
您可以添加server_name localhost;
您server
添加的块,这样请求就不会碰到default_server
块。
一般来说,应该始终server_name
在 nginx 中指定。
答案2
我相信你正在default. conf
运行
include /etc/nginx/conf.d/*.conf;
你可以检查一下nginx -T | more
要禁用此文件,只需将其移动mv /etc/nginx/conf.d/default.conf /root
,然后重新加载service nginx reload
希望能帮助到你