[英]nginx redirects to subfolder for prettier links
I have a question concerning nginx redirects / try_files: 我有一个关于Nginx重定向/ try_files的问题:
I have a website (vhost managed by ISPConfig3) at www.XXXYYY.com 我在www.XXXYYY.com有一个网站(由ISPConfig3管理的虚拟主机)
In the root directory there are folders, index.php and so on. 在根目录中,有文件夹index.php等。
I want certain files in www.XXXYYY.com/folder21/public/309273.php
to be accessible at www.XXXYYY.com/309273
(to have prettier links). 我想在某些文件
www.XXXYYY.com/folder21/public/309273.php
是在访问www.XXXYYY.com/309273
(有漂亮的链接)。
However, everything I tried yet did either not work at all or the .php-files got downloaded instead of being processed by PHP-FPM… 但是,我尝试过的所有操作都根本不起作用,或者下载了.php文件,而不是由PHP-FPM处理...
This is the nginx vhost directive I'm currently trying out in ISPConfig3: 这是我目前正在ISPConfig3中尝试的nginx vhost指令:
This is being set by ISPConfig3: 这是由ISPConfig3设置的:
location ~ \.php$ {
try_files @php;
}
location @php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9026;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
This is the part that is being added by me at the bottom of the vhost-file: 这是我在vhost文件底部添加的部分:
location / {
try_files $uri $uri/ /folder21/public/$uri.php /index.php =404;
}
location /folder21/ { internal; }
location /folder21/public/ {
try_files $uri $uri/ $uri.php;
}
Any help on this is appreciated! 任何帮助对此表示赞赏!
This is what I ended up with for pydio : 这就是我为pydio最终得到的 :
location /conf/ { deny all; }
location /data/ { internal; }
location /data/public/ {
try_files $uri $uri/ $uri.php?$args;
rewrite ^/data/public/([a-z0-9]+)-([a-z]+)$ /data/public/$1.php?lang=$2 last;
}
location ^~ /share/ {
rewrite ^/share/(.*)$ /data/public/$1 last;
}
PHP-files in /data/public
are now served through /share
without the need of the .php-ending. /data/public
中的PHP文件现在可以通过/share
而无需.php结尾。
Files in the format of eg /data/share/XYZ123-en
are being rewritten to /data/share/XYZ-123.php?lang=en
. 格式为
/data/share/XYZ123-en
将被重写为/data/share/XYZ-123.php?lang=en
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.