【发布时间】:2015-12-04 07:12:44
【问题描述】:
我正在尝试将 nginx 配置为从 2 个不同的位置提供 2 个不同的 php 脚本。配置如下。
- 我有一个 Laravel 安装,它位于
/home/hamed/laravel中,应该在其中提供其public目录。 - 我在
/home/hamed/www/blog中安装了 Wordpress。
这是我的nginx 配置:
server {
listen 443 ssl;
server_name example.com www.example.com;
#root /home/hamed/laravel/public;
index index.html index.htm index.php;
ssl_certificate /root/hamed/ssl.crt;
ssl_certificate_key /root/hamed/ssl.key;
location /blog {
root /home/hamed/www/blog;
try_files $uri $uri/ /blog/index.php?do=$request_uri;
}
location / {
root /home/hamed/laravel/public;
try_files $uri $uri/ /index.php?$request_uri;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.hamed.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
问题是当尝试通过调用example.com/blog 访问 wordpress 部分时,laravel 安装仍然接管了请求。
现在我尝试用 alias 替换 location 块内的 root 指令,但无济于事。
根据this guide 在location 中包含index 指令或try_files 会触发内部重定向,我怀疑这会导致此行为。
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: php nginx nginx-location