S
S
Seboreia2014-05-14 14:47:37
Nginx
Seboreia, 2014-05-14 14:47:37

How to configure upstream server ports in Nginx?

Greetings!
There is a bunch of tomcat + nginx. Tomcat has opencms installed and multisite: i.e. there are several http connectors:
etc.
Accordingly, Nginx has proxying:
server {
listen 80;
server_name www.site1.ru;
gzip off;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml text/css;
access_log logs/host.www.site1.ru.access.log main buffer=32k;
location /export/ {
proxy_pass 127.0.0.1:8081/export/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /resources/ {
proxy_pass 127.0.0.1:8081/resources/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /opencms/ {
rewrite ^/opencms/(.*)$ www.site1.ru/$1 permanent;
}
location / {
root html;
index index.html index.htm;
proxy_pass 127.0.0.1:8081/opencms/;
client_max_body_size 200m;
client_body_buffer_size 128k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
} etc.
Those. Each site has its own port.
The question arose as follows: how to balance on a tomcat cluster? Let's say I do this:
upstream appservers {
server tomcat1
server tomcat2
}
server {
location / {
proxy_passhttp://appservers;
}
}
Then how to pass the uri part and the port? As I understood from the docks, it is impossible to write proxy_pass appservers:8081/export . Is there any way to solve this?
There was an idea to put an nginx on each tomcat in the cluster and then add each of them to the group for balancing at the main one (which will look outside). The idea is working, but not rational)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Zhivotnev, 2014-05-14
@inkvizitor68sl

You can do this:

upstream blahupstr {
server tomcat1:8081;
server tomcat2:8082;
}

server {
...
proxy_pass http://blahupst/export/ ;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question