Ngnix oldjira.domain.com:port rewrite to new.domain.com

Ali YILMAZ March 9, 2018

Hi,

It is also for new.domain.com:8080 to new.domain.com. However, here is my nginx conf;

 

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name jira.domain.com www.jira.domain.com;
return 301 https://$server_name$request_uri;

location / {
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_pass http://jira.domain.com;
client_max_body_size 10M;
}

}


server {
listen 443 ssl;
server_name jira.domain.com;
ssl_certificate /etc/pki/tls/ssl/ssl_certificate.crt;
ssl_certificate_key /etc/pki/tls/ssl/private.key;
ssl_trusted_certificate /etc/pki/tls/ssl/IntermediateCA.crt;
# NGINX usually only allows 1M per request. Increase this to JIRA's maximum attachment size (10M by default)
client_max_body_size 10M;

location / {
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_pass http://localhost:8080;
}

location /kb {
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_pass http://localhost:8090/kb;
}
}

In this configuration, everthing works fine. I'm wondering is it possible forwarding jira.domain.com:8080 to jira.domain.com? I've tried almost everything. 

1 answer

0 votes
Craig Castle-Mead
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 10, 2018

Hey Ali,

Something like the below should work - only listens for requests from oldjira.domain.com and then redirects to new.domain.com which will then be handled by the server blocks you've referenced above.

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  server_name oldjira.domain.com;
  return 301 https://new.domain.com$request_uri;

}

 

CCM

Ali YILMAZ March 10, 2018

Thank you so much but it will be duplicated when i add those. I've tried like that;

 

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name new.domain.com www.new.domain.com oldjira.domain.com;
return 301 https://$server_name$request_uri;

...

In this case, oldjira.domain.com redirected to new.domain.com, ok but I want oldjira.domain.com:8080 to new.domain.com. Is it possible? 

When I try to access to oldjira.domain.com:8080 I'm getting new jira but logins not working because of the base URL. Please check attached ss.oldjira.png

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 11, 2018

You should not be doing this with proxies or rewrites, you need to use absolute redirects.  When a user lands on <old url>, they should be fully redirected to <new url>, not have the server present the old url on the new one.  Anything browser landing on <old url> should have the address changed to <new url>

Craig Castle-Mead
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2018

Ali,

since only one application can bind to a port (8080) which for your current config is Jira - and it won’t/can’t (that I know of) force a redirect to the baseURL, I see two options.

1 - change the DNS on oldjira.domain.com to another server that can have nginx/Apache listen on :8080 and handle the redirect

2 - change your new JIRA port from 8080  to something else, point your current proxypass value from 8080 to the new port. Once you’ve done this, you’ll be able to get your current nginx to listen on :8080 and redirect to newjira.donain.com

 

With both options, you should pretty much just need to change the listen directive in the example I posted earlier from 80 to 8080

(https://serverfault.com/questions/655067/is-it-possible-to-make-nginx-listen-to-different-ports)

 

CCM

Ali YILMAZ March 13, 2018

Hi, 

Thank you, I was wondering if it's possible to make on the same server.

Thanks again. 

Suggest an answer

Log in or Sign up to answer