A
A
Alexander Pashchenko2016-01-16 20:45:16
Nginx
Alexander Pashchenko, 2016-01-16 20:45:16

How to force nginx to give a separate folder for domain.com/sub?

We have a project in Laravel.
And it took a part of requests for / sub to be processed by a separate script. But bad luck, a separate script is also written in Laravel and is essentially an independent project.
I just can't get my brain to figure out how to change the nginx config to make everything work. Help to understand, please.
Now the config is standard like everyone else:

server {
# все как у всех
   listen 80 default_server;
   server_name domain.cm;
   root /home/domain.com/public;
   index index.php;

# тут все стандартно 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

# и тут все стандартно 
   location ~ \.php$ {
       fastcgi_pass 127.0.0.1:9001;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
   }
}

Accordingly, /home/domain.com is the project. And /home/domain.com/public is the entry point to the application.
And so in /home/domain.com/sub there is a subproject. And its entry point is naturally /home/domain.com/sub/public
And you need to give it as domain.com/sub. And so that the user does not redirect to domain.com/sub/public
I tried to implement what I need like this:
location /sub {
         alias /home/domain.com/sub/public/;
         try_files $uri $uri/ /index.php?$query_string;
 }

Does not work.
Tried like this:
location /sub {
       root /home/domain.com/sub/public/;
       rewrite ^(.*) /index.php$1;
  }

Doesn't matter.
I feel that the solution is simple and should be on the surface. Well, it's like a thorn in my head. When you know a word, but you can't remember.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Kravchenko, 2016-01-20
@kruff

proxy_pass?

A
Alexander Pashchenko, 2017-07-31
@point212

It's funny. The same question came up again. It’s useful to ask a question, but it turns out that everything is already there. For over a year now. And the situation is one on one. Only in a different place with different people and a different project.
I don’t know if the question will rise from the comment to the top in the search results. But it's as relevant as ever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question