nginx & WordPress 无法正常工作(子文件夹)



我有一个在子文件夹(/tips(中有wordpress的网站,但我无法让它在nginx上正常工作。在Chrome中,它或多或少可以工作,但在Edge上它根本不起作用。

它位于带有php5的Ubuntu 16.04上。

我试图让它与 wordpress.org 上的文档一起工作(位置 =/tips(,但它只有 404。因此,我不得不使用重写,如下所示。

这是现有的nginx配置:

server {
listen 443 ssl;
server_name  www.domain.co.uk;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
root /var/www/domain.co.uk;
index index.php;
ssl on;
ssl_certificate /etc/nginx/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl/www_domain_co_uk.key;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS +RC4 RC4";
ssl_prefer_server_ciphers on;
location / {
    try_files $uri $uri.html $uri/ =404;
}
location ~ .php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/run/php/php5.6-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    include fastcgi_params;
}
rewrite ^/tips/(.*) /tips/index.php?$args;
if (!-f $request_filename) {
    set $rule_3 1$rule_3;
}
if (!-d $request_filename) {
    set $rule_3 2$rule_3;
}
if ($uri !~ ".*.(ico|gif|jpg|jpeg|png|js|css)") {
    set $rule_3 3$rule_3;
}
if ($rule_3 = "321") {
    rewrite ^/([^?]*) /index.php?_route_=$1 last;
}
location ~* .(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           30d;
}

}

您要为与现有文件匹配的每个调用返回 404?

location / {
    try_files $uri $uri.html $uri/ =404;
}

看起来每个转到/tips 的页面都会被重定向回/tips...

这确实看起来像一个无限的重定向

rewrite ^/tips/(.*) /tips/index.php?$args;

快速谷歌建议类似的东西,但同样我不是 100% 确定您要实现的目标

location /tips/ {
    try_files $uri /index.php$args =404;
}

找出问题所在 - 这是与核心站点重写(对于 opencart(的冲突。修复如下:

location / {
    try_files $uri $uri/ @opencart;
}
location @opencart {
    rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
location /tips/ {
    try_files $uri $uri/ /tips/index.php?$args;
}

最新更新