A
A
afna2017-07-12 16:25:48
Nginx
afna, 2017-07-12 16:25:48

How to set up 2 locations with proxy_pass?

Hello!
I'm trying to separate requests into api and dev . Each location proxies to its own application.
nginx config file:

server {
 listen 80;
 listen [::]:80;
 server_name some.domain;

 server_tokens off;
 root /var/www/html;

  location /api {
   proxy_pass_request_headers    on;
   proxy_pass http://localhost:1337;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection 'upgrade';
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade; 
 }

  location /dev {
   proxy_pass_request_headers    on;
   proxy_pass http://localhost:1338;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection 'upgrade';
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade; 
 }
}

Is it possible to share like this?
How to configure redirect uri to pass_proxy?
If I request some.domain/api/uri_1 , then localhost:1337/api/uri_1 is proxied , but I need it without /api.
I tried to do it through rewrite like this:
location /api {
   rewrite ^ /api([0-9a-z]*) $1 break;
   proxy_pass_request_headers    on;
   proxy_pass http://localhost:1337;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection 'upgrade';
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade; 
 }

As a result of the experiments, a whole day was spent and 404, 500, 502 from nginx and 404 from the application were received.
What should be the settings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shatokhin, 2017-07-12
@Sovigod

Add at the end / Like this
:
proxy_pass localhost:1338/;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question