场景描述:一个域名abc.com,两个项目。通过abc.com访问项目1,abc.com/abc/访问项目二;
server {
listen 8080;
listen [::]:8080;
server_name www.abc.com;
access_log /data/wwwlogs/nginx.log combined;
index index.html index.htm index.php;
#项目一地址
root /data/wwwroot/port8080/project_1/public;
location / {
try_files $uri $uri/ /index.php?s=$uri&$args;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
#第二个项目/abc/访问
location /abc/ {
alias /data/wwwroot/port8080/project_2/public/;
try_files $uri $uri/ /abc/index.php$is_args$args;
location ~ \.php$ {
#根据自己的服务器定
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
if (!-e $request_filename){
rewrite ^/abc/(.*)$ /bike/index.php?s=/$1 last;
}
}
}
完美解决!