子目录网站CMS的NGINX配置不会删除/index.php/

时间:2018-10-31 09:25:33

标签: docker nginx url-rewriting

我当前用于在Docker服务器上的子目录中托管网站的NGINX配置似乎不起作用。我尝试了几件事,但没有结论。

server {
    root /www;
    access_log /logs/access.log;
    error_log /logs/error.log debug;
    index index.html index.php;
    if ($bad_referer) { return 444; }

    # Enable PHP with path_info for any php subfolder
    location ~ ^(.+\.php)($|/) {
        fastcgi_pass archives_php:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_intercept_errors on;
        include /nginx/fastcgi_params;
    }


    ###
    ### SPECIFIC SITE
    ###
    # Cockpit
    location = /site { try_files $uri /site/index.php$uri?$args; }
    location /site {
        try_files $uri $uri/ /site/index.php$uri?$args;
        location ~ ^(.+\.php)($|/) {
            fastcgi_pass archives_php:9000;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_intercept_errors on;
            include /nginx/fastcgi_params;
        }
    }
    location /site/cockpit { try_files $uri $uri/ /site/cockpit/index.php; }


    # Assets disabled logging and expiration max
    include /nginx/assets.conf;
}

# Anti spam referrals
include /nginx/referral-spam.conf;

使用dubsomain.site.com/site/index.php/page时,该网站可以正常运行,但这不是我想要的行为。

一个具有相同CMS但位于根文件夹中的相似网站就像一个超级按钮。

1 个答案:

答案 0 :(得分:0)

如果您需要将URI的一部分附加到/site/index.php,则需要使用正则表达式。

例如:

location /site {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^/site(.*)$ /site/index.php$1 last;
}

location = /site是不必要的,除非需要执行URI的特定操作,并且嵌套在location ~ ^(.+\.php)($|/)块中的第二个location /site块永远不会被调用,并且被相同,反正是不必要的。