Currently, I am able to visit: https://files.mydomain.com/files
. Even if I go to https://files.mydomain.com
, it will redirect automatically to https://files.mydomain.com/files
successfully.
Instead, I would like for NGINX to automatically rewrite https://files.mydomain.com/files
-> https://files.mydomain.com
My current NGINX code:
http {
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
server {
listen 80;
server_name files.mydomain.com;
location / {
return 301 https://files.mydomain.com$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name files.mydomain.com;
client_max_body_size 0;
location / {
return 301 https://$host/files;
}
location /files {
proxy_pass http://localhost:89;
}
}
#Root Domain
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name_in_redirect off;
server_name www.mydomain.com mydomain.com;
log_not_found off;
location / {
root /inetpub/wwwroot;
index index.html index.htm;
}
}
}
My best attempt:
Unfortunately, it just takes me to the "Welcome to NGINX" webpage when I visit:
https://files.mydomain.com
http {
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
server {
listen 80;
server_name files.mydomain.com;
location / {
return 301 https://files.mydomain.com$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name files.mydomain.com;
client_max_body_size 0;
location ^~ /files {
rewrite ^/files/?(.*)$ https://files.mydomain.com/$1 permanent;
proxy_pass http://localhost:89/files;
}
}
#Root Domain
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name_in_redirect off;
server_name www.mydomain.com mydomain.com;
log_not_found off;
location / {
root /inetpub/wwwroot;
index index.html index.htm;
}
}
}