里雲centOS7.4配置多個站點遇到的問題
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2
這個錯誤好尷尬,
費了幾個小時去解決,小白呀沒辦法
先貼下/etc/nginx/nginx.conf的內容
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/vhost/*.conf;
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/vhost/*.conf;
}
}
vhost/mayifa.conf內容
server
{
listen 80;
server_name localhost;
root /data/www/mayifanx;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
就這個配置好好的,systemctl restart nginx ,依照命令使用systemctl status nginx.service
檢測為什么為老是報錯
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2

所以nginx.conf中server節點的 include /etc/nginx/vhost/*.conf; 應該被刪掉
正確的/etc/nginx/nginx.conf配置如下
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/vhost/*.conf;
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
}
}
systemctl restart nginx
終於正常了。
可以使用 nginx -t -c /etc/nginx/nginx.conf 這個檢測配置是否正常,今天才明白nginx.conf配置是把你指定include配置一起包含的,類似C++中的include
