2

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?

3
  • Very good question. It needs quite good work to make laravel app with another app work on same virtualhost Commented Apr 24, 2015 at 13:54
  • what you want is an alias, leave your root as /var/www/ and add a location as location /my_project { alias /var/www/my_project/public; } Commented Apr 24, 2015 at 13:59
  • Fabio, that is one of the configurations I have tried, but it doesn't work. http://my_domain.com/my_project/ returns the nginx/Ubuntu 404 page. Thank you for the suggestion though! Commented Apr 24, 2015 at 14:14

2 Answers 2

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.