裏雲centOS7.4配置多個站點遇到的問題
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2
這個錯誤好尷尬,
費了幾個小時去解決,小白呀沒辦法php
先貼下/etc/nginx/nginx.conf的內容html
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內容nginx
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:2bash
因此nginx.conf中server節點的 include /etc/nginx/vhost/*.conf; 應該被刪掉app
正確的/etc/nginx/nginx.conf配置以下spa
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 rest
終於正常了。code
可使用 nginx -t -c /etc/nginx/nginx.conf 這個檢測配置是否正常,今天才明白nginx.conf配置是把你指定include配置一塊兒包含的,相似C++中的includeserver