我想在Ubuntu 16.04(Ubuntu-NGINX-MariaDB-PHP)上托pipe多个WordPress网站。 我不想使用WordPress的多站点。
我遵循这个指南 。 一切都很好,但我只能托pipe一个网站。 每当我创build多个服务器块configuration,它开始显示错误,NGINX无法启动。 我没有得到我的configuration文件正确。 这里是configuration文件:
server { listen [::]:80 ipv6only=off; server_name abcde.org www.abcde.org; root /var/www/abcde; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. # try_files $uri $uri/ =404; try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: # fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }
如果我只有一个网站,它工作正常。 但是,一旦我主持另一个网站,NGINX无法启动。 在更改服务器名称和根目录后,我对两个站点使用相同的configuration。
请引导我进行NGINX服务器模块的正确configuration。
你的nginx.config需要类似这样的一行。 这是我在我的服务器上做的
include /etc/nginx/enabled-sites/*;
在那个目录中,你可以有一个文件与多个服务器,或者你可以做我做的事情,并按照域来分组服务器。
文件abcde.conf
server { listen 80; server_name www.abcde.org; root /var/www/home; # Any locations you want. PHP example that I use below. location ~ \.php$ { fastcgi_keep_conn on; fastcgi_intercept_errors on; fastcgi_pass php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } # ends www.abcde.org server # This server forwards to the www domain server { listen 80; server_name abcde.org; return 301 https://www.abcde.org$request_uri; } # ends abcde.org server
文件example.conf
# server for a completely separate domain server { listen 80; server_name www.example.com; root /var/www/example; # Any locations you want } # ends www.example.com server
文件default_server.conf
# This just prevents Nginx picking a random default server if it doesn't # know which server block to send a request to server { listen 80 default_server; server_name _; # This means "go away", effectively. You can also forward somewhere # or put default_server onto any of your server blocks. return 444; }