我认为这是一种基本内容,但是我正在努力寻找可以解释这些事情的正确指南:
我有一个index.php
文件和nginx
配置,以便https://dev.something.com
工作正常。
但是我需要更改nginx
配置,以便该地址生成空白页,而index.php
仅从https://dev.something.com/lists
起作用。我可以将index.php
放入列表目录中,但是没有更多细微的解决方案吗?
这是困难的部分:用户应该能够访问
https://dev.something.com/lists/userName
https://dev.something.com/lists/userName/listName
userName
和listName
应用作GET
-Parameters。
任何人都可以帮助我如何使用nginx
实现这种配置?
您是在问一些(相对基本的)问题,我建议您从他们的免费电子书https://www.nginx.com/blog/announcing-oreillys开始-new-book-nginx-a师范对高表现/
您可以定义nginx在何处使用root子句查找索引文件,尽管它们通常相对于server
的root使用URL上下文,但可以在每个位置覆盖。
http://nginx.org/en/docs/http/ngx_http_core_module.html#root
您可以将部分URL用作变量,也可以作为参数传递。
location = /lists { # '=' will match exactly, no trailing url
root /path/where/index.php/lives;
try_files $uri /index.php;
}
location /lists { # this will match anything under that url
rewrite ^/lists/(d+)/?$ /lists?user=$1; # matches username
rewrite ^/lists/(d+)/(d+)/?$ /lists?user=$1&list=$2; # matches username/list
}
location /{ #everything else
root /path/where/index.html/lives; #index.html is empty file.
try_files $uri /index.html;
}