'IIS rewrite or redirect request to docker container or nginx
i got 2 servers, the first is a default cofigured exchange 2019 srv with ssl (default iis). Second one is docker host running on a ubuntu 20.04 with native nginx and serveral containers like bitbucket , bamboo.
so i got follwing hosts :
srv1: 192.168.1.5 (Exchange 2019) srv2: 192.168.1.248 (ubuntu with native nginx + docker-host)
bitbucket container : 192.168.1.248:7990 bamboo container : 192.168.1.248:8085
My nginx conf on srv2 :
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
ssl_password_file path/to/pass;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 0;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
for example my nginx bitbucket conf:
server {
listen 443 ssl;
server_name bitbucket.mydomain.com;
ssl_certificate /path/to/*.crt;
ssl_certificate_key /path/to/*.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://192.168.1.248:7990;
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;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
}
My router is configured so that 192.168.1.5 is the default DMZ, so mydomain.com will be redirected to the excahnge srv.
In every guide its required to setup a new site and bind port 80/443 but in my case exchange already blocks this ports and i need to configure it so that requests for subdomains got redirected or rewrite to my nginx srv so that nginx can redirect to the right docker container.
i've installed url rewrite and ARR3 module on my exchange server. In IIS i clicked on URL Rewrite inside "Default Web Site" and added a "Reverseproxy" rule with ssl-offloading. The created rule contain the pattern (.*), and now i added the following condition : {HTTP_HOST} = ^(?!www)(.bitbucket).mydomain.com$
and as action "rewrite" with following url : "http://192.168.1.248"
if i try to access now bitbucket.mydomain.com it doesen't redirect/or rewrite to my docker container, instead its redirect me to "https://bitbucket.mydomain.com/owa/auth/logon.aspx" and owa shows up and i'm completly confused whats going on.
Could anyone help me with this configuration ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
