Reputation: 97
I have placed my Laravel 5 project in /var/www/my_project/
and I would like to reach it at http://my_domain.com/my_project/
. However, I can't figure out how to configure the nginx server block.
What I want is this:
http://my_domain.com/
should be empty at this point. Later, another project will be visible here.http://my_domain.com/my_project/
should be the project I am trying to add now.Please note that the Laravel public folder is located at /var/www/my_project/public
.
This is my nginx configuration (at /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;
}
}
What is the best way to achieve the desired configuration?
Upvotes: 2
Views: 3934
Reputation: 639
This worked for me. And other answers didn`t woked
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;
}
}
Upvotes: 0
Reputation: 3625
If you want to put your laravel
project in a subfolder
on a server with ngnix-ubuntu 16-php.7.2
, so here is update ngnix config :
1) your nested(subfolder) isn't inside your main folder
/var/www/main:
/var/www/nested:
then your config :
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) your laravel-test folder (subfolder) inside your main :
/var/www/main:
/var/www/main/nested:
then your config :
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;
}
Upvotes: 1