【发布时间】:2016-11-27 13:03:21
【问题描述】:
这是我原来的nginx配置
server {
listen 80;
server_name my-site.com;
return 301 http://www.my-site.com$request_uri;
}
server {
listen 80;
server_name www.my-site.com;
root /var/www/sites/mysite/public_html;
index index.php index.html index.html;
access_log /var/log/nginx/mysite.access.log;
error_log /var/log/nginx/mysite.error.log;
ssl off;
location / {
try_files $uri $uri/ index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_read_timeout 180;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
然后我想在子文件夹中添加另一个站点让我们说 "my-site.com/another_app" 但是这个站点需要重写 url,例如:
my-site.com/another_app/api
my-site.com/another_app/home
变成
my-site.com/another-app/api.php
my-site.com/another-app/index.php?mod=home
我已经尝试像这样在 "location /" 中添加重写
location / {
try_files $uri $uri/ index.php;
rewrite ^/another-app/api$ /another-app/api.php break;
rewrite ^/another-app/([A-Za-z0-9-|_]+)/?$ /another-app/index.php?mod=$1 break;
}
但每次我尝试访问 "my-site.com/another-app/api" 时都会触发下载 php 脚本
我错过了什么吗?
【问题讨论】:
-
尝试使用
last而不是break(假设两个应用程序共享同一个文档根目录。详情请参阅this document。 -
我尝试使用 last 但仍然触发脚本 donwload