我在 centos8 stream 上通过 yum install nginx
安装了 nginx,通过命令 sudo netstat -plutn | grep nginx
检查,nginx 是正常运行的
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9962/nginx: master
配置文件 nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
而 conf.d
中的唯一配置文件 xc.conf
server {
listen 80;
return 403;
}
即通过 ip 访问,则得到 403 的返回。
现在遇到的问题是,通过 ip 访问,并不能得到 403 的返回。而访问 ip:8080 能正常访问到一个通过 docker 拉起来的应用。
感觉 nginx 虽然是运行了,但并没有正常工作。
PS, 所有的端口都已经打开
请问这个该怎么排查呢?多谢。
nginx -T
先检查一下配置文件,有没有多出来的东西。怀疑是改错了文件,或者改了配置之后没有重新加载配置。按照现在的配置,应该是只要访问80端口,都会返回403。