0

Не могу понять как скрыть часть url для пользователей. Есть ссылки вида:

site.com/www/site1/index1.php
site.com/www/site2/index2.php

Нужно переделать сиё чудо в

site.com/index1.php
site.com/index2.php

Конфигурация такая: nginx (front) - nginx (back) - php-fpm

Фронт проксирующий:

location / {
  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP       $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        X-Forwarded-Proto https;
  proxy_pass              http://172.18.1.1:1234;
}

Бэк работает через сокет:

location / {                                             
  try_files           $uri $uri/ =404;         
}                                                                                                                  

location ~ \.php$ {                                                        
  include             fastcgi_params;                                    
  fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass        unix:/var/run/php-fpm.sock;                        
  fastcgi_read_timeout 300s;                                             
  fastcgi_send_timeout 300s;                                             
}   

Затупок мой в том, что я не понимаю как сделать, чтоб для нескольких директорий php отрабатывал. Т.е. конструкция данного вида не работоспособна:

location / {                                             
  try_files           $uri $uri/ =404;         
}                                                

location ~ /www/site1/\.php$ {                                                                  
  root /dir/to/www/site1;                                               
  include             fastcgi_params;          
  fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass        unix:/var/run/php-fpm.sock;                        
  fastcgi_read_timeout 300s;                                             
  fastcgi_send_timeout 300s;                                             
}     

...                                                                     

location ~ \.php$ {                                                        
  include             fastcgi_params;                                    
  fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass        unix:/var/run/php-fpm.sock;                        
  fastcgi_read_timeout 300s;                                             
  fastcgi_send_timeout 300s;                                             
}  

1 ответ 1

0

Задачу решил таким кодом

rewrite ^/www/site1/$ /test1/ last;           

location ~ /test1/(.*\.php)$ {                   

  alias /app/www/site1/$1;                  

  include             fastcgi_params;          
  fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass        unix:/var/run/php-fpm.sock;                        
  fastcgi_read_timeout 300s;                                             
  fastcgi_send_timeout 300s;                                             
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.