I want to make an development environment like this.
http://local-a.com -> redirects to localhost:8080
https://local-a.com -> redirects to localhost:8443
http://local-b.com -> redirects to localhost:8090
https://local-b.com -> redirects to localhost:9443
http://local-c.com -> redirecnts to localhost:8100
https://local-c.com -> redirects to localhost:10443
Can you suggest how to do that?
It seems /etc/pf.conf file and /etc/hosts files can do this but I am very confused about how to do this.
Just a few guides of links would be helpful for me.
Thank you.
reference: https://apple.stackexchange.com/questions/332145/mapping-port-80-to-8080-but-maintain-explicit-8080-access
Ok. I clear my question by this method.
/etc/hosts
127.0.0.1 local-a.com
127.0.0.1 local-b.com
127.0.0.1 local-c.com
using nginx.conf
server {
listen 80;
server_name local-a.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Front-Server-Ip $remote_addr;
proxy_set_header X-Forwarded-Proto 'http';
proxy_pass http://localhost:8080;
}
}
server {
listen 80;
server_name local-b.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Front-Server-Ip $remote_addr;
proxy_set_header X-Forwarded-Proto 'http';
proxy_pass http://localhost:8090;
}
}
...
Related
In our system, each tenant has their own page at specific port:
Tenant 1000 -> https://[ip]:1000
Tenant 1001 -> https://[ip]:1001
Tenant 1xxx -> https://[ip]:1xxx
Now we want access to these instances via subdomain:
https://t1000.mydomain.com
https://t1001.mydomain.com
https://t1xxx.mydomain.com
So my question is: how to config Nginx to map subdomain into port dynamically?
https://t1000.mydomain.com -> https://[ip]:1000
https://t1001.mydomain.com -> https://[ip]:1001
https://t1xxx.mydomain.com -> https://[ip]:1xxx
I finally found a way to do this:
server {
listen 80;
server_name ~^t(?<port>[^.]+)\.mydomain\.com$;
location / {
proxy_pass http://localhost:$port;
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-Proto $scheme;
}
}
I am new in nginx. I want to rewrite
feature-1234.mydomain.com/xyz?foo=bar
to
docker-feature-1234:9000/xyz?foo=bar
with request parameters.
I use official nginx docker image. How should be my nginx.conf file?
EDIT: 'feature-1234' is a variable so:
feature-5678.mydomain.com
should serve as
docker-feature-5678:9000
By combining answers, i found the solution.
https://serverfault.com/questions/388552/nginx-sub-domain-proxy-pass
Docker Network Nginx Resolver
nginx: [emerg] "server" directive is not allowed here
nginx.conf:
events {
}
http {
server {
listen 80;
server_name ~(.*).test.go;
location / {
if ($host ~* ^([a-zA-Z0-9-]+)\.test\.go$) {
set $proxyhost docker-$1:9000;
}
resolver 127.0.0.11 ipv6=off;
proxy_pass http://$proxyhost;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}
}
}
Thanks
I've installed a sonarqube and a Jenkins server in one machine, with ports 9000 and 8080 respectively. I'd like to make urls like test_hub.mysite.com/sonar and /jenkins and redirect to machine and port correctly, but maintaining original address test_hub.mysite.com/sonar.
My configuration with nginx is pretty simple:
server {
listen 80;
server_name sonar.mysite.com;
location /sonar/ {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://52.29.xx.xx:9000;
}
}
server {
listen 80;
server_name test_hub.mysite.com;
location / {
# you can use regular exp also
if ($request_uri = /sonar) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://52.29.xx.xx:9000;
}
if ($request_uri = /jenkins) {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://52.29.xx.xx:8000;
}
}
}
NOTE: Check this link before trying
I want to use nginx to redirect (or proxy) request from 7443 to 8443.
https://serverIP:7443/oldApp/ ==> https://serverIP:8443/new/app/
I've tried some of settings, but still got 404 or empty page.
Here are my nginx config:
//ssl settings ..
server {
listen [::]:7443 ipv6only=off ssl;
server_name localhost;
location /oldApp/ {
proxy_set_header Accept-Encoding "";
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-Proto $scheme;
#proxy_set_header X-Forwarded-Port 8443;
#add_header Front-End-Https on;
proxy_pass https://127.0.0.1:8443/new/app;
}}
And here are some assumptions that might be helpful for directive usage:
for different port/scheme => use proxy_pass (or proxy_redirect)
for different virtual host/subdomain/folder => use sub_filter (or rewrite?)
Are those assumptions correct?
Thanks in advance!
I fixed this as below:
server {
listen [::]:7443 ipv6only=off ssl;
server_name localhost;
location ^~ /oldApp {
proxy_pass https://127.0.0.1:8443/new/app/;
# Here is the trick: add the port behind $host
proxy_set_header Host $host:8443;
# This make sure your session won't lose
proxy_cookie_path ~*^/.* /;
}}
Many thanks
I would like to redirect all http traffic to https with a handful of exceptions. Anything with /exception/ in the url I would like to keep on http.
Have tried the following suggested by Redirect all http to https in nginx, except one file
but it's not working. The /exception/ urls will be passed from nginx to apache for some php processing in a laravel framework but that shouldn't matter.
Any suggestions for improvement much appreciated!
server {
listen 127.0.0.1:80;
location / {
proxy_pass http://127.0.0.1:7080;
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-Accel-Internal /internal-nginx-static-location;
access_log off;
}
location /exception/ {
# empty block do nothing
# I've also tried adding "break;" here
}
return 301 https://localhost$request_uri;
}
Nginx finds the longest matching location and processes it first, but your return at the end of the server block was being processed regardless. This will redirect everything but /exception/ which is passed upstream.
server {
listen 127.0.0.1:80;
access_log off;
location / {
return 301 https://localhost$request_uri;
}
location /exception/ {
proxy_pass http://127.0.0.1:7080;
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-Accel-Internal /internal-nginx-static-location;
}
}