我已将我的Laravel 5项目放在/var/www/my_project/
中,我想在http://my_domain.com/my_project/
处找到它。但是,我无法弄清楚如何配置nginx服务器块。
我想要的是:
http://my_domain.com/
应为空。稍后,这里将显示另一个项目。http://my_domain.com/my_project/
应该是我现在要添加的项目。请注意,Laravel公用文件夹位于/var/www/my_project/public
。
这是我的nginx配置(/etc/nginx/sites-enabled/
):
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/my_project/public;
index index.php index.html index.htm;
server_name my_ip;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
实现所需配置的最佳方法是什么?
答案 0 :(得分:1)
如果您想将laravel
项目放在具有subfolder
的服务器上的ngnix-ubuntu 16-php.7.2
中,那么这里是update ngnix config:
1)您嵌套的(子文件夹)不在主文件夹中
/var/www/main:
/var/www/nested:
然后配置:
location /nested {
alias /var/www/nested/public;
try_files $uri $uri/ @nested;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}
2)您主目录中的laravel-test文件夹(子文件夹):
/var/www/main:
/var/www/main/nested:
然后配置:
location /laravel-test {
alias /var/www/main/laravel-test/public;
try_files $uri $uri/ @laravelTest;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @laravelTest {
rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}
答案 1 :(得分:0)
这对我有用。和其他答案没有醒来
location /rmbdatamis/ {
root /home/baiduwork/rmb-odp/webroot;
index index.php;
include fastcgi.conf;
fastcgi_pass $php_upstream;
if (!-e $request_filename){
rewrite ^/rmbdatamis/(.*) /rmbdatamis/index.php?/$1 last;
}
}