我在 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;
}