A
A
Al2017-02-07 20:00:01
Nginx
Al, 2017-02-07 20:00:01

How to register multiple directories for the front in NGINX?

There is a config

upstream cp_io_nodes {
    	  ip_hash;
    	  server 127.0.0.1:6001;
    	  server 127.0.0.1:6002;
    	  server 127.0.0.1:6003;
    	  server 127.0.0.1:6004;
    	  server 127.0.0.1:6005;
    	  server 127.0.0.1:6006;
    	  server 127.0.0.1:6007;
    	  server 127.0.0.1:6008;
    }
    
    server {
    	listen *:3001; ## listen for ipv4
    	server_name *.mysite.com;
    	access_log off;
    	error_log /var/log/nginx/error-mysite-node-qa.log; 
    	location / {
    		proxy_pass http://cp_io_nodes;
    		proxy_set_header Host $host;
    		proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header X-Forwarded-For $remote_addr;
    		proxy_connect_timeout 120;
    		proxy_send_timeout 120;
    		proxy_read_timeout 180;
    	}
     
    	location ~* \.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs)$ {
    		root /mysite_data/mysite/app/www;
    		expires max;
    	}
    
    }

The problem is that there are several subdomains, and for each the front is taken from different folders in the location:
/mysite_data/mysite/app/www;
/mysite_data/mysite/subdm2/app/www;
/mysite_data/mysite/subdm3/app/www;

Here's how to make it search for files in all folders?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2017-02-07
@ky0

try_files ? But in general, this is the wrong approach, to take at least the option when the names of the files in the directories are the same.
Make better separate configs for subdomains.

V
Viktor Taran, 2017-02-08
@shambler81

nginx developer philosophy - it's easier to copy the config than to have a bunch of regular expressions.
Now to the point.
1. Troubles will remain during generation, for example, variables will not appear in the root log because this is a string and put x on variables.
But if you already have an admin panel, and it generates coffins, then it would not be sour to announce it. and throw a couple of configs. domain and subdomain.
3. The easiest way
man - ln- standard, cheap and cheerful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question