nginx redirect (or proxy) to another localhost app
January 10, 2021 04:16AM
hi! beginner here. Is it possible in nginx to have path /appA, /appB map to localhost:9090 and 9191 respectively?

i just wanted to redirect a path named /appA and /appB to localhost:9090 and 9191 but it
returned 404 and i dont want it to be like localhost:9090/appA

appA is phoenix app (localhost:9090)
appB is also phoenix app in localhost:9191

upstream phoenix {
server localhost:9090;
}

upstream homepage {
server localhost:9191;
}

server {
listen 80;
listen [::]:80;

server_name domain.tld;
return 404;
}

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

server_name domain.tld;

ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

# ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
# ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://homepage;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# asset delivery
# location ~* ^.+\.(css|cur|gif|gz|ico|jpg|jpeg|js|png|svg|woff|woff2)$ {
# root /home/user/public;
# etag off;
# expires max;
# add_header Cache-Control public;
# }
}

location /phoenix {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://phoenix;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# asset delivery
location ~* ^.+\.(css|cur|gif|gz|ico|jpg|jpeg|js|png|svg|woff|woff2)$ {
root /home/user/app/priv/static;
etag off;
expires max;
add_header Cache-Control public;
}
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 74
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready