我有一个nginx网络服务器,我想在其上运行多个laravel项目
第一个项目工作正常,但第二个项目只打开主页,主页地址
example.com/secondproject/
但是当我想打开时
example.com/secondproject/foo
nginx将跳过/ secondproject别名并在第一个项目中查找请求的路由(nginx配置中的服务器根目录)
这是我的配置
server {
listen 80;
server_name example.com;
rewrite_log on;
location / {
root /path/to/first-project/public;
index index.php index.html index.htm;
try_files $uri $uri/ $uri/index.php /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
location /secondproject {
alias /path/to/second-project/public;
index index.php;
location /secondproject {
try_files $uri $uri/ $uri/index.php /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
}
当我替换
root /path/to/second-project/public;
而不是
alias /path/to/second-project/public;
nginx显示403!
答案 0 :(得分:0)
尝试这样:
server {
listen 80;
server_name example.com www.example.com;
location / {
root /path/to/first-project/public;
index index.php index.html index.htm;
try_files $uri $uri/ $uri/index.php /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
# ------- second
location /secondproject {
root /path/to/second-project/public;
index index.php index.html index.htm;
try_files $uri $uri/ $uri/index.php /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
}