![WordPress 站点的 NGINX 配置部分只能通过单独的域名访问](https://linux22.com/image/754337/WordPress%20%E7%AB%99%E7%82%B9%E7%9A%84%20NGINX%20%E9%85%8D%E7%BD%AE%E9%83%A8%E5%88%86%E5%8F%AA%E8%83%BD%E9%80%9A%E8%BF%87%E5%8D%95%E7%8B%AC%E7%9A%84%E5%9F%9F%E5%90%8D%E8%AE%BF%E9%97%AE.png)
我在 Ubuntu 20.04 NGINX 服务器上安装了一个 WordPress。大多数 WordPress 页面应通过主域 example.com 访问,但部分页面只能通过第二个域 example.net 访问。我应如何修改当前的 NGINX 配置以实现此目的?我应在一个目录中仅安装一个 WordPress(test.example.com 除外)。
server {
listen 80;
server_name www.example.com;
# www to non-www for SEO canonical reasons
return 301 http://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
root /var/www/example.com/html;
index index.php index.html index.htm index.nginx-debian.html;
# PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
}
# (For WordPress permalinks)
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
}
server {
listen 80;
server_name test.example.com;
root /var/www/example.com/test;
index index.php index.html index.htm index.nginx-debian.html;
# PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
}
# (For WordPress permalinks)
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
}
答案1
新的服务器块是解决方案:
server {
listen 80;
server_name www.example.net;
root /var/www/example/othersection;
}