F
F
frolin2017-04-14 15:58:03
Nginx
frolin, 2017-04-14 15:58:03

NGINX rewrite and proxy subdomain to subdirectory?

Greetings. There was a necessity to make so:
There is a subdomain, demo.site.ru.
There are sites /app1 and /app2.
Make rewrite and send to the right places turned out.
But neither styles nor scripts are loaded, they go to the base subdomain demo.site.ru/js and, accordingly, are not available. should be demo.site.ru/app1/js.

Example config for app1:

upstream unicorn_app1_production {
  server unix:/tmp/unicorn.app1_production.sock fail_timeout=0;
}
                                                                
                                                                              
server {                                                                      
                                                                              
  listen 80;                                                                  
                                                                              
                                                                              
  client_max_body_size 25M;                                                   
  keepalive_timeout 10;                                                       
                                                                              
  server_name www.demo.site.ru demo.site.ru;                            
                                                                              
location /app1/ {                                                      
 root /var/www/apps/demo/app1/current/public;                          
 rewrite ^/app1/(.*) /$1  break;                                       
 rewrite_log on;                                                              
                                                                              
 proxy_pass http://unicorn_app1_production;                         
                                                                              
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                 
 proxy_set_header Host $http_host;                                            
 proxy_redirect off;                                                          
 proxy_set_header X-Real-IP  $remote_addr;                                    
 proxy_set_header X-Forwarded-Proto $scheme;                                  
                                                                              
 access_log /var/log/nginx/app1/app1_production.access.log;     
 error_log /var/log/nginx/app1/app1_production.error.log;       
}


I'm trying to add another rewite: .js, .css by analogy, but it doesn't work out.
rewrite ^\.(js|css|jpg)$ /$1 break;
Can you tell me how to properly taxi the request?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question