L
L
LegeArtis2019-02-04 20:55:21
Nginx
LegeArtis, 2019-02-04 20:55:21

How to redirect some requests to another port?

Nginx is installed on the VM. It is necessary to redirect some of the requests to another port. I created the /etc/nginx/conf.d/example.conf file
and here it is

server{
listen 443;
location /findByFId {
proxy_pass http://хх.ххх.хх.хх:4444/;
proxy_redirect off;
}
}

api replaced with "x" for the post
I realized that I wrote the question incorrectly, I will add information. I have a website that is on this Nginx and Api for communication with the database that is on the same VM on Node.js, Api, in turn, listens to port 4444, I took a LetsEncrypt certificate for the domain and now when a request is made from the site to port 4444, it is blocked because the request to port 4444 is http. After studying this issue, I came to the conclusion that I need to send all requests to https (port 443) and then filter and redirect them. There can be standard requests from the site, such as Add, findId, and so on. I have never dealt with Nginx before. Therefore, I will formulate the questions specifically.
1. Have I correctly decided that I need to create a file in this folder? /etc/nginx/conf.d/example.conf
2. The option that is in the example does NOT work. What's wrong with him? If yes, please provide an example of a similar redirect.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Syomov, 2019-02-04
@LegeArtis

If this part of the requests is to the same address, then this can be done using the upstream block, and specify not a specific ip/port in proxy_pass, but a group of servers.
Different servers in a group may not necessarily be different servers, but simply different ports on the same ip.
more details in the documentation: https://nginx.org/ru/docs/http/ngx_http_upstream_m...
If to different addresses, create different locations that will receive the necessary requests and proxy to the necessary ports.

B
bigbn, 2019-02-04
@bigbn

You can add another location directive to another path and, by analogy, make proxy_pass to the desired port.

location /findByName {
   proxy_pass http://хх.ххх.хх.хх:4445
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question