I have setup a docker environment for testing nginx reverse proxy.
Instead of setting up a subdomain for every backend, i would like to have 1 subdomain with a location pointing to the individual backend:
while this works as expected:
server {
listen 80;
server_name dashboard.test.lan;
location / {
proxy_pass http://172.17.0.1:82;
}
}
server {
listen 80;
server_name gitlab.test.lan;
location / {
proxy_pass http://172.17.0.1:83;
}
}
server {
listen 80;
server_name portainer.test.lan;
location / {
proxy_pass https://172.17.0.1:9443;
}
}
...this does not work:
server {
listen 80;
server_name proxy.test.lan;
location /dashboard {
proxy_pass http://172.17.0.1:82;
}
location /gitlab {
proxy_pass http://172.17.0.1:83;
}
location /portainer {
proxy_pass https://172.17.0.1:9443;
}
}
Maybe you guys can give me a hint or explanation why this does not work.
Related
I want to pass requests like this:
http://mydomain.io --> http://127.0.0.1:8080
http://mydomain.io/aa/bb --> http://127.0.0.1:8080/aa/bb
http://api.mydomain.io --> http://127.0.0.1:10000
http://api.mydomain.io/cc/dd --> http://127.0.0.1:10000/cc/dd
and my /etc/nginx/conf.d/default.conf file:
listen 80;
server_name mydomain.io;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
server_name api.mydomain.io;
location ~ ^/(.*)$ {
proxy_pass http://127.0.0.1:10000/$1;
}
}
When I send request to http://api.mydomain.io:10000/xxx, it works,
but http://api.mydomain.io/xxx doesn't work.
(It returns 502 Bad Gateway Error)
What is the problem with my config file?
default.conf
server { # This one before the wilcard domain
listen 80;
server_name api.mydomain.io;
location / {
proxy_pass http://127.0.0.1:10000;
}
}
server { # always at the end
listen 80 default_server;
server_name *.mydomain.io;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
Hi I am facing issue when configuring nginx as proxy server to redirect request to my tomcat server. I have 3 tomcat server running on different machine & different port like this
192.168.51.115:8115
192.168.51.120:8120
192.168.51.130:8130
Now I want to config nginx to pass request to my three server sequentially like this
www.example.com/app1
www.example.com/app2
www.example.com/app3
Real IP: 123.123.123.123
This is my configuration under - site-enabled
server {
listen 80;
server_name example.com www.example.com;
location /app1 {
proxy_pass "http://192.168.51.115:8115";
}
location /app2 {
proxy_pass "http://192.168.51.120:8120";
}
location /app3 {
proxy_pass http://192.168.51.130:8130;
}
}
Note: When i put location directive placing just / then it works but doesn't work on /* like app1,app2 or app3
Can you try using ^~ as modifier in your location block ?
like
server {
listen 80;
server_name example.com www.example.com;
location ^~ /app1 {
proxy_pass "http://192.168.51.115:8115";
}
location ^~ /app2 {
proxy_pass "http://192.168.51.120:8120";
}
location ^~ /app3 {
proxy_pass http://192.168.51.130:8130;
}
}
like these:
test1.sec.com 192.168.1.8:8001<br>
test2.sec.com 192.168.1.8:8002<br>
test3.sec.com 192.168.1.8:8003<br>
http://www.sec.com/test1/ 192.168.1.8:8001<br>
http://www.sec.com/test2/ 192.168.1.8:8002<br>
http://www.sec.com/test3/ 192.168.1.8:8003<br>
how to config the nginx.conf ?
You haven't provided much information, but based on what you gave, this should work:
server {
listen 80;
server_name test1.sec.com;
location / {
proxy_pass http://192.168.1.8:8001;
}
}
server {
listen 80;
server_name test2.sec.com;
location / {
proxy_pass http://192.168.1.8:8002;
}
}
server {
listen 80;
server_name test3.sec.com;
location / {
proxy_pass http://192.168.1.8:8003;
}
}
Then, for your www.sec.com, you'll need to add separate location blocks to catch the /test/ URIs.
server {
listen 80;
server_name www.sec.com;
location /test1/ {
redirect 301 $scheme://test1.sec.com;
}
location /test2/ {
redirect 301 $scheme://test2.sec.com;
}
location /test3/ {
redirect 301 $scheme://test3.sec.com;
}
#Rest of your config here...
}
Note: You have to specify your test location blocks before your root (/) unless you use a modifier to give them precedence.
This is my nginx conf file.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:9000;
}
location /some/directory {
proxy_pass http://localhost:8998;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://localhost:8999;
}
}
For some reason example.com and example2.com are working, but example.com/some/directory is not.
localhost:9000 & localhost:8999: are harp.js sites, they have they own routing, and work properly, both locally and on the proxy-ed domains (example.com & example2.com).
localhost:8998: is a golang api, it works locally and also if I access example.com:8998 or example2.com:8998.
Is there something wrong with the conf?
EDIT: added more info to the question.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:9000/;
}
location /some/directory {
proxy_pass http://localhost:8998/;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_pass http://localhost:8999/;
}
}
Try this, adding the last / in the proxy_pass's should work.
I want to have two Play Framework deployments on the same server and configure nginx to redirect the locations accordingly.
I have this configuration:
server {
listen 80;
server_name localhost;
client_max_body_size 20M;
location /site2 {
proxy_pass http://localhost:8000/;
}
location / {
proxy_pass http://localhost:9000/;
}
}
But it does not work.
What I want is:
When I use: http://ip/ or http://ip/something the Play deployment at port 9000 should respond.
When I use: http://ip/site2/ or http://ip/site2/something the Play deployment at port 8000 should respond.
First, please check that you have access to each app directly:
ip:8000
ip:9000
Next please add proxy_redirect directive:
server {
listen 80;
server_name localhost;
location /site2 {
proxy_pass http://localhost:8000/;
proxy_redirect http://localhost/site2/ http://localhost:8000/;
}
location / {
proxy_pass http://localhost:9000/;
proxy_redirect http://localhost/ http://localhost:9000/;
}
}