I
I
Ilya Chichak2017-05-30 12:29:53
Django
Ilya Chichak, 2017-05-30 12:29:53

How to implement application functioning as in a subfolder in nginx?

I have an application that runs on a domain (for example, example.com ). you need to make another application on the example.com/new-app domain (in this case, this is a completely separate application, in no way connected with the one on example.com).
in the nginx configuration for example.com, there is location /new-app , which makes a proxy_pass to the example.com:8080 domain, where the second application is available. I pull statics and so on through try_files (like if there are such files here, use them, otherwise go to /new-app/static). it works. The problem is that the paths are written like this: /login. and this /login leads to example.com/login, but I need it to lead to example.com/new-app/login. how can this be done?

server {
        listen 80;
        server_name example.com;
        access_log /var/log/nginx/example.log;

        location /static/{
                root /srv/example/files/;
                try_files $uri /new-app/$uri;
                expires 30d;
        }
        location /media/{
                root /srv/example/files/;
                try_files $uri /new-app/$uri;
        }
        location / {
                proxy_pass http://unix:/srv/example/example.sock;
                proxy_set_header Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /new-app/static/ {
                root /srv/new-app/files/;
                expires 30d;
        }
        location /new-app/media/ {
                root /srv/new-app/files/;
        }
        location /new-app/ {
                proxy_pass http://example.com:8080/;
        }
}

server {
        listen 8080;
        server_name example.com;
        access_log /var/log/nginx/new-app.log;

        location /static/{
                root /srv/new-app/files/;
                expires 30d;
        }
        location /media/{
                root /srv/new-app/files/;
        }
        location /{
                proxy_pass http://unix:/srv/new-app/new-app.sock;
                proxy_set_header Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

maybe there are other suggestions

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