NGINX try_文件,名称为$uri中的最后一个单词

NGINX try_文件,名称为$uri中的最后一个单词,nginx,location,reverse-proxy,nginx-reverse-proxy,nginx-config,Nginx,Location,Reverse Proxy,Nginx Reverse Proxy,Nginx Config,我的服务器上有一个nginx,我试图让它打开文件“/config/www/pp1/index.php”作为地址,打开文件“/config/www/interpreter/index.html”作为地址。此外,所有类似的东西都应该启动“/config/www/interpreter/res/docs.html”。我做了很多尝试。当前,我在/site confs中的默认配置文件如下所示: server { listen 80; listen 443 ssl http2

我的服务器上有一个nginx,我试图让它打开文件“
/config/www/pp1/index.php
”作为地址,打开文件“
/config/www/interpreter/index.html
”作为地址。此外,所有类似的东西都应该启动“
/config/www/interpreter/res/docs.html
”。我做了很多尝试。当前,我在/site confs中的默认配置文件如下所示:

server {
        listen 80;
        listen 443 ssl http2;
        server_name kni.mini.pw.edu.pl;

        # Path for SSL config/key/certificate
        ssl_certificate /config/keys/cert.crt;
        ssl_certificate_key /config/keys/cert.key;

        location / {
                proxy_read_timeout    90;
                proxy_connect_timeout 90;
                proxy_redirect        off;
                proxy_pass http://kni_website;
                proxy_set_header      X-Real-IP $remote_addr;
                proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header      Host $host;
        }

         location /pp1 {
                root /config/www;
                index index.html index.htm index.php;
                try_files $uri $uri/ index.php $uri/index.php /config/www/pp1/index.php index.php; #/index.php?$args =404;
                location ~ \.php$ {
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        # With php5-cgi alone:
                        fastcgi_pass 127.0.0.1:9000;
                        # With php5-fpm:
                        #fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        include /etc/nginx/fastcgi_params;
                }
        }
         location /interpreter {
                if ($request_uri ~* "([^/]*$)" ) {
                        set  $last_path_component  $1;
                }
                root /config/www;
                index index.html index.htm index.php $last_path_component.html;
                try_files /interpreter/res/$last_path_component.html $uri.html $uri.html $uri $uri/ /index.html index.php /$uri.html  /index.php?$args =404;
                location ~ \.php$ {
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        # With php5-cgi alone:
                        fastcgi_pass 127.0.0.1:9000;
                        # With php5-fpm:
                        #fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        include /etc/nginx/fastcgi_params;
                }
        }

}

server {
        listen 80 default_server;

        listen 443 ssl;

        root /config/www;
        index index.html index.htm index.php;

        server_name _;

        ssl_certificate /config/keys/cert.crt;
        ssl_certificate_key /config/keys/cert.key;

        client_max_body_size 0;

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

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;

        }
}
坦率地说,我原以为我知道自己在做什么,但现在我非常确定位置块
位置/解释器
根本没有被检查,而且
位置/pp1
的内部正在引起一些疯狂的混乱


请帮助一个需要帮助的新手

主要问题是
try\u files
将在当前上下文中处理其文件元素,因此无法在同一语句中处理
.html
.php
URI。有关详细信息,请参阅

一种解决方案是使用命名位置将
try\u files
语句一分为二。首先测试
$uri
$uri.html
$uri/index.html
,然后测试
$uri.php
$uri/index.php

例如:

root /path/to/root;

location /foo {
    try_files $uri $uri.html $uri/index.html @php;
    location ~* ^(.*)\.php$ { return 301 $1; }
}
location @php {
    try_files $uri.php $uri/index.php =404;
    fastcgi_pass  ...;
    ...
}

添加了
location~*^(.*)\.php$
块以正确处理以
.php
结尾的URI。最简单的解决方案是将它们重定向到一个URI,并删除
.php

谢谢!它现在可以工作了,但是我必须导航到(末尾有斜杠)-当我导航到(没有斜杠)时它不工作。有没有像重写这样的方法来解决这个问题?我的意思是
https://example.com/pp1/
我希望可以从
https://example.com/pp1
(末尾没有斜杠)奇怪地
curl-Ihttps://kni.mini.pw.edu.pl/pp1
显示它重定向到
http
。您的问题或我的答案中的配置不应该这样做。此服务器正在终止SSL连接吗?我在其他人管理的代理后面。我无法了解他/她如何处理ssl证书机器人程序。然而,我的问题与此无关,我相信(或者不是??)。我想要uri:
https://kni.mini.pw.edu.pl/pp1
https://kni.mini.pw.edu.pl/pp1/
。第一个总是被当作是
https://kni.mini.pw.edu.pl
。问题是否与以下事实有关:在location/下有一个docker与wordpress一起驻留?您是否仍在使用
$uri/
作为
try\u files
语句中的文件术语之一?