Good day!

The question is, in fact, in the following:

There are two sites on the same domain. One is located in the root folder of the domain, and the second in a virtual subfolder. Nginx config

server { listen 443 ssl http2; server_name www.example.ru; root /var/www/example; index index.php; location / { root /var/www/example; index index.php index.html index.htm; rewrite ^/api/(.*)$ /api.php?_d=$1&ajax_custom=1&$args last; try_files $uri $uri/ @fallback; location /catalog { root /var/www/example; index index.php index.html index.htm; try_files $uri $uri/ @fallback; } } 

As a result, both sites open at example.ru and example.ru/catalog

But!

example.ru/catalog is looking for pictures, js files, etc. in the / var / www / example / catalog directory, which does not exist. All its files are a higher level (/ var / www / example /). How to make the subdirectory look at the level above so that it sees all the necessary files?

Thank!

Upd:

It turned out to solve part of the problem by adding below

 location ~ ^/catalog/(.+\.(?:gif|jpe?g|png|js|css|svg|ttf))$ { alias /var/www/example/$1; } 

After that, the necessary files became visible.

There is a problem with the arguments going after index.php

Example: https://example.ru/catalog/index.php?dispatch=ab__grid_tabs.load&block_id=298&result_ids=content_ab__grid_tab_2379_298&is_ajax=1

Gives 404 to the console. Because of this, part of the functionality and content of the site https://example.ru/catalog disappears.

The index.php file itself is physically located here: https://example.ru/index.php

Is it possible to solve such a problem through the nginx configuration?

  • alias instead of root - andreymal
  • @andreymal if put alias instead of root, then example.ru/catalog ceases to open with an error 404 - Pomut
  • If these are two different sites, then better duplicate files and do not show off) - andreymal
  • @andreymal if this were realizable, I would take the path of least resistance and would not ask here. - Pomuth
  • Completed the question - Otmut

1 answer 1

Solved the problem by changing the location

c

 try_files $uri $uri/ @fallback; 

on

 # Π›ΠΎΠ³ΠΈΠΊΠ° поиска скрипта ΠΏΠΎ порядку: Ρ„Π°ΠΉΠ», ΠΏΠ°ΠΏΠΊΠ°, скрипт try_files $uri $uri/ /$1/$3 /$2/$3 $3 @fallback; 

Where

 location @fallback { rewrite ^/(\w+/)?(\w+/)?(.*)$ /$1/index.php?$args last; rewrite ^/(\w+/)?(\w+/)?(.*)$ /index.php?$args last; } 

With statics it helped:

 location ~* /(\w+/)?(\w+/)?(.+\.(jpe?g|ico|gif|png|css|js|pdf|txt|tar|wof|woff|svg|ttf|csv|zip|xml|yml)) { access_log off; try_files $uri $uri/ /$1/$3 /$2/$3 $3 @statics; expires max; add_header Access-Control-Allow-Origin *; add_header Cache-Control public; } 

Where

 location @statics { rewrite ^/(\w+/)?(\w+/)?(.*)$ /$1/$3 break; access_log off; try_files $uri $uri/ /$1/$3 /$2/$3 $3 @fallback; rewrite_log off; expires max; add_header Cache-Control public; add_header Access-Control-Allow-Origin *; }