通常在CentOS上我们采用默认方式安装nginx:yum install nginx,安装完成后,进行server配置,然后将测试网页上传到服务器对应的目录下,启动nginx服务。
这时候,我们从后台可以看到nginx服务已经启动了,但是访问网站就是无法显示测试网页index.html的信息,返回页面仍然是nginx的测试页面,到底是怎么回事呢?
[root@hamster1 ~]# ps -ef | grep nginx
root 6310 5816 0 20:45 pts/0 00:00:00 grep --color=auto nginx
root 20882 1 0 12月18 ? 00:00:00 nginx: master process nginx
nginx 21094 20882 0 12月18 ? 00:00:00 nginx: worker process
其实很简单,我们只需要在配置文件中注释下面这一行,并重启nginx服务即可:
#include /etc/nginx/conf.d/*.conf;
全部的配置文件如下:
nginx version: nginx/1.20.2
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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 {
listen 80;
server_name xxxx.com;
location / {
root /data/www;
index index.html;
}
}
}