I've got a problem in configuration nginx proxy_pass. There's a situation like this:
Server 1 - xx.xx.xx.xx - proxy server
Server 2 with application A - yy.yy.yy.yy
Server 3 with application B - zz.zz.zz.zz
Configuration listed below:
server {
listen 80; ## listen for ipv4; this line is default and implied
location /app_a {
rewrite /app_a/(.*)$ /$1 break;
access_log off;
proxy_pass http://yy.yy.yy.yy/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Upstream $remote_addr;
}
location /app_b {
rewrite /app_b/(.*)$ /$1 break;
access_log off;
proxy_pass http://zz.zz.zz.zz;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Upstream $remote_addr;
}
}
Then when I go with my browser xx.xx.xx.xx/app_a or xx.xx.xx.xx/app_b there is no static files loaded (404) and all links are without application prefix (xx.xx.xx.xx/login)
How I can configure nginx so the links will be displayed like:
xx.xx.xx.xx/app_a/login
xx.xx.xx.xx/app_b/login
Related
I have two node js apps that I want to put behind nginx.
I access application 1 which has "/" as a base and I access its pages which are on /be/ but when I try to go to application 2 automatically I am referred to "/".
summary
App1:
based:"/"
url: localhost:3003
application pages can be found in /be/
App2:
base:"/be/"
url: localhost:3000/be/login
the application pages can also be found on /be/
here is my nginx config
server {
listen 80;
server_name 192.168.1.64;
access_log /var/log/nginx/portalerr.logs;
error_log /var/log/nginx/portalaccess.logs;
location / {
proxy_pass http://192.168.1.64:3003/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
}
location /login/ {
proxy_pass http://192.168.1.64:3000/be/login;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite /be/login(.*) /$1 break;
proxy_cache_bypass $http_upgrade;
}
}
I'm trying to serve some services as a subdomain but it looks like nginx is not doing it right.
I have 3 docker containers serving zabbix, webmin and mediawiki.
example.com/zabbix (works fine)
example.com/webmin (not rendering)
example.com/wiki (not rendering)
server {
listen 80;
server_name example.com;
root /var/www/html/;
location /zabbix {
proxy_pass http://192.168.0.71:8081;
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 /wiki {
proxy_pass http://192.168.0.71:8080;
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 /webmin {
proxy_pass http://192.168.0.71:10000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Also add in /etc/webmin/config:
webprefix=/webmin
webprefixnoredir=1
and LocalSettings.php
$wgServer = "http://example.com";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
wiki pages and webmin looks weird:
wiki screenshot
Any help will be appreciated
thanks!
I have a host with two containers:
nginx
check_mk
the check_mk interface is accessible by http://172.17.0.2:5000/cmk
I have proxy_pass rule set up in nginx:
server {
listen 80;
server_name cmk.domain.com;
location / {
proxy_pass http://172.17.0.2:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
When I hit the nginx on port 80 with cmk.domain.com/cmk it works.
What I want is that when hitting the server_name cmk.domain.com, the /cmk would be added automatically.
I tried doing proxy_pass http://172.17.0.2:5000/cmk; but then I get a page not found error.
What am I missing here?
Try this
server {
listen 80;
server_name cmk.domain.com;
location /cmk {
proxy_pass http://172.17.0.2:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location / {
return 301 http://cmk.domain.com/cmk$request_uri;
}
}
I want to redirect my http://127.0.0.1:9090/data/admin/ to http://94.162.152.12:9090/admin/ that can be access outside in my network. I already open port 9090 in my router.
Take a look my nginx config
server {
listen 9090;
server_name 94.162.152.12;
location ~* /data/admin/ {
proxy_pass http://127.0.0.1:9090;
proxy_redirect off;
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_set_header X-NginX-Proxy true;
}
}
In case you mean proxying from http://94.162.152.12:9090/admin/ to http://127.0.0.1:9090/data/admin/ you might want to do it as follow:
server {
listen 9090;
server_name 94.162.152.12;
location /admin {
rewrite ^/admin/(.*) https://127.0.0.1:443/data/admin/$1 permanent;
proxy_pass http://127.0.0.1:9090;
proxy_redirect off;
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_set_header X-NginX-Proxy true;
}
}
This will rewrite all requests for /admin/* to /data/admin/* and call localhost as backend.
I have very limited knowledge with rewriting url in nginx. I have a plex media server running behind on nginx, i can access the dashboard with http://domain.com/web/index.html with these config i found on github:
upstream plex-upstream {
server plex-server.example.com:32400;
}
server {
listen 80;
server_name domain.com
location / {
if ($http_x_plex_device_name = '') {
rewrite ^/$ http://$http_host/web/index.html;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_pass http://plex-upstream;
}
}
What i want is to remove /web/index.html so when i go to http://domain.com, the PMS dashboard will load. I tried some one liner rewrite rules already but all failed. Thanks.
I am not nginx specialist, but I had similar problem.
The diference is that I was not trying to alias domain.name/ to domain.name/web/,
My goal was to alias domain.name/plex/ to domain.name/web/.
I was getting redirects to web/index.html with all solutions I could find except this one Configure Plex Media Server Reverse Proxy nginx Linux.
The only one problem with this one was that if you go to web/ you will stay there.
So here is my creepy yet working solution:
upstream plex {
server localhost:32400;
}
server {
listen 80;
server_name domain.name;
server_name_in_redirect off;
location / {
proxy_pass http://localhost:8888;
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_set_header X-NginX-Proxy true;
# Enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
location /web/index.html {
if ($http_x_should_not_redirect = ""){
return 301 https://domain.name/plex/index.html;
}
proxy_pass https://plex;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header x_should_not_redirect $host;
}
location /web {
proxy_pass https://plex;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header x_should_not_redirect $host;
}
location /plex {
proxy_pass https://127.0.0.1/web;
proxy_set_header X-should-not-redirect $host;
}
location /transmission/rpc {
proxy_pass http://localhost:9091;
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_set_header X-NginX-Proxy true;
# Enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
location /transmission/web {
proxy_pass http://localhost:9091;
proxy_pass_header X-Transmission-Session-Id;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/dovgastreetnas.viewdns.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dovgastreetnas.viewdns.net/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}
Hope this will help somebody.