通常在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;
}
}
}