F
F
Flaker2016-08-08 14:07:34
linux
Flaker, 2016-08-08 14:07:34

How to configure nginx to handle different routes with different fastcgi?

I read about how location works , but for some reason, when going to sub.site.local/hotels , " location / {} " is still processed , and not " location / hotels {} ", although the hotels prefix is ​​longer.
How to send requests to different php-fpm?
Current config:

server {
  listen 80;

  server_name sub.site.local;
  index       index.php;

  client_max_body_size 100M;
  fastcgi_read_timeout 1800;

  location /hotels {
    root        /projects/newsite/public;
    try_files $uri $uri/ /index.php?$query_string;
    add_header X-location newsite;

    include       fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass  cabinet:9000;
  }


  location / {
    root        /projects/oldsite;
    try_files $uri $uri/ /index.php?$query_string;
    add_header X-location oldsite;

    include       fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass  agent:9000;
  }
}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nikolayvaganov, 2016-08-08
@nikolayvaganov

Is there a /hotels directory physically?

V
Vovanys, 2016-08-08
@Vovanys

Knock on the door
In the config:
server_name sub.site.local
And you climb site.local/hotels

D
demsi, 2016-08-08
@demsi

I advise you to add access_log to locations. To determine exactly which location the request goes to. After proper configuration, the main thing is not to forget to remove them.
Headers can get into the cache, they are more difficult to determine.
According to this config, when requesting sub.site.local/hotels, nginx should execute the /projects/newsite/public/hotels/index.php file in fastcgi , if it exists.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question