为多个位置创建正则表达式捕获。
树结构:
/home/user/webapps/
├── index.html <= content: root.
├── osqa
│ ├── index.html <= content: osqa test A.
│ ├── osqa <= django project
│ │ ├── index.html <= content: osqa test B.
│ │ └── osqa
│ │ ├── settings.py
│ │ └── wsgi.py
│ ├── run
│ └── static
└── forum
├── index.html <= content: forum test A.
├── forum <= django project
│ ├── index.html <= content: forum test B.
│ └── forum
│ ├── settings.py
│ └── wsgi.py
├── run
└── static
这个 nginx 配置正在工作:
server {
listen 8080;
server_name localhost;
root /home/user/webapps/;
location /osqa/ {
alias /home/user/webapps/osqa/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass h ttp://unix:/home/user/webapps/osqa/run/gunicorn.sock:/;
}
location /forum/ {
alias /home/user/webapps/forum/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass h ttp://unix:/home/user/webapps/forum/run/gunicorn.sock:/;
}
试图将这些位置加入一个 PCRE 正则表达式
location ~ webapps\/(?P<app>[\w-_]+) {
alias /home/user/webapps/$app/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass h ttp://unix:/home/user/webapps/$app/run/gunicorn.sock:/;
}
我得到了什么:
localhost:8080/osqa/osqa/
returns: osqa test B
localhost:8080/osqa/
returns: 403 Forbidden
localhost:8080
returns: osqa test A
我所期望的:
localhost:8080/osqa/osqa/
returns: osqa test B
localhost:8080/osqa/
returns: django site
localhost:8080
returns: root
我阅读了有关用户 dir、location、SF post 的信息,但仍然不知道该怎么做。
我应该添加或更改什么,我应该在哪里查看?(我几乎没有想法)
匹配是针对规范化的 URI 而不是根路径执行的。
所以这
应该
及其现在的工作。