设想
在 mydomain.com 上托管一个域名
根目录是 /var/www/mydomain/wordpress,指向 mydomain.com
希望路径:/var/www/site2/wordpress 指向 mydomain.com/site2
对于我在 /var/www/ 中建立的其他目录,依此类推(即 /var/www/site3、site4 等到 mydomain.com/site3、site4)
站点启用文件
以下是 /etc/nginx/sites-available 中的配置文件
server {
root /var/www/mydomain/wordpress;
index index.php;
server_name mydomain.com www.mydomain.com;
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
location /site2 {
root /var/www/site2/wordpress;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mydomain.com www.mydomain.com;
return 404; # managed by Certbot
}
我尝试调整 site2 的 /location 以使用别名和根,并删除 $uri,但要么出现 404,要么重定向到 /var/www/mydomain/wordpress 存储库的 wordpress 404 页面未找到。似乎发生了重定向,但我并不知道。
任何帮助,将不胜感激。