ThinkPHP 5.0 项目 A 路径为:/www/a
,运行目录为 /www/a/public
ThinkPHP 5.0 项目 B 路径为:/www/b
,运行目录为 /www/b/public
为了能使两个项目使用同一个域名,项目 A 的 Nginx 配置内,将 请求 /go/
URL 的所有请求通过 proxy_pass 转发给项目 B 处理,也就是希望访问 http://example.com/go/
时,实际访问的是项目 B 的运行目录 /www/b/public
PHP-FPM 开了 pathinfo,而且项目 A 已经成功跑起来了,而项目 B 所有响应都是 404 并有文字输出 File not found
(不是浏览器默认的 404 页面)。
ThinkPHP 5.0 默认的 URL 规则是这样的:
访问 http://example.com/test
,相当于访问 http://example.com/index.php/test
server {
listen 80;
server_name example.com;
root /www/a/public;
location ^~ /go/ {
proxy_pass http://localhost:81;
}
location / {
index index.php;
try_files $uri $uri/ /index.php$request_uri;
}
location ~* \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|bmp|png|webp|gif|svg|ico|js|css|eot|woff|woff2|ttf|otf) {
add_header Cache-Control max-age=2592000;
etag on;
access_log off;
log_not_found off;
}
}
项目 A 按照上面的 Nginx 配置,已经成功运行起来。
server {
listen 81;
server_name localhost;
root /www/b/public;
location / {
index index.php;
try_files $uri $uri/ /index.php$request_uri;
}
location ~* \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|bmp|png|webp|gif|svg|ico|js|css|eot|woff|woff2|ttf|otf) {
add_header Cache-Control max-age=2592000;
etag on;
access_log off;
log_not_found off;
}
}