【发布时间】:2019-07-21 19:53:18
【问题描述】:
我想在一个由 NGINX 服务器块(不是默认站点)配置的域上同时运行 WordPress 和 YOURLS。由于两者都需要以不同的方式处理 URL,因此它们需要不同的 try_files 指令。 WordPress 位于域的根目录 (domain.tld),而 YOURLS 被安装到 /g/ 目录。尽管有两个位置规则,但我在 YOURLS 生成的任何链接(例如 domain.tld/g/linkname,都是重定向到外部 URL)上得到 404,尽管我可以访问管理后端。
据我所知,声明位置规则(一个用于 /g/,一个用于 /)应该足以让 NGINX 以不同方式处理直接和 /g/ URL - 我的想法有什么问题吗?
try_files 规则是正确的,并且在其他单应用程序服务器块上运行良好(WordPress 以及 YOURLS 在单独的服务器块上安装)。
服务器块定义配置如下所示:
server {
listen [::]:80;
listen 80;
server_name domain.tld www.domain.tld;
return 301 https://domain.tld$request_uri;
}
server {
listen [::]:443 ssl;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
root /var/www/html/domain.tld;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name domain.tld www.domain.tld;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
}
location /g/ {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
expires 14d;
add_header Cache-Control 'public';
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
【问题讨论】: