use*_*859 1 ubuntu nginx virtualhost wordpress
我想在 Ubuntu 16.04 (Ubuntu-NGINX-MariaDB-PHP) 上托管多个 wordpress 网站。我不想使用 wordpress 多站点。
我遵循了本指南。一切都很好,但我只能托管一个站点。每当我创建多个服务器块配置时,它就会开始显示错误并且 NGINX 无法启动。我的配置文件不正确。这是配置文件:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我只托管一个网站,它工作正常。但是一旦我托管另一个网站,NGINX 就无法启动。更改服务器名称和根目录后,我对两个站点使用相同的配置。
请指导我正确配置 NGINX 服务器块。
您的 nginx.config 需要类似这一行的内容。这就是我在我的服务器上所做的
include /etc/nginx/enabled-sites/*;
Run Code Online (Sandbox Code Playgroud)
在该目录中,您可以拥有一个包含多台服务器的文件,或者您可以按照我的操作将服务器按域分组。
文件 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
Run Code Online (Sandbox Code Playgroud)
文件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
Run Code Online (Sandbox Code Playgroud)
文件 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8984 次 |
| 最近记录: |