我想在NGINX中使用别名函数来完成一些简单的事情。 我在过去的3天里search了互联网,发现只有不好的或过时的例子,希望有人可以发布一个基于新版本NGINX的工作示例。
我有以下url:
http://mysite.com/ username_123
我的问题是如何使NGINX将此请求转发到内部用户文件夹:
html / profiles / username_123
…并返回其index.php页面?
请记住,这个index.php页面被传递到监听127.0.0.1:9000的php FastCGI服务器
有趣的是,我有同样的问题find有关Apache风格别名或脚本别名有用的信息。 最近我结束了关于它的博客 。
这与nginx版本1.0.5进行了testing,但也应该工作在0.85。
server { listen 80; server_name localhost; index index.html index.php; root /var/www; location ~ ^/username_123(.*)\.php($|/) { include php_fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/html/profiles/username_123$1.php; } location ~ ^/username_123(.*) { autoindex on; alias /var/www/html/profiles/username_123$1; } }