T
T
Thomas Storm2016-09-12 11:18:46
Nginx
Thomas Storm, 2016-09-12 11:18:46

How to redirect a request from example.com/site to example.com?

Hello!
Our old jira was available at https://jira.example.com/jira
The new jira was available at https://jira.example.com.
How can I set up a reverse proxy on nginx so that it listens to the address https://jira.example.com and redirects all incoming requests to https://jira.example.com/jira and my address is https://jira.example.com
Reverse proxy config:

upstream Jira_upstream  {
      server some_ip:80;
}

server {
    listen       some_ip:80;
    server_name  jira.example.com;

    return 301 https://$host/;
}

server {
    listen some_ip:443;
    server_name jira.example.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example-com-new.crt;
    ssl_certificate_key /etc/nginx/ssl/example-com-new.key;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   

    client_max_body_size 32m;

    location / {
      proxy_set_header        Host $server_name;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $remote_addr;
      proxy_redirect          http:// https://;
      proxy_pass              http://Jira_upstream/;
    }

}

server {
    listen some_ip:8443;
    server_name jira.example.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example-com-new.crt;
    ssl_certificate_key /etc/nginx/ssl/example-com-new.key;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    

    client_max_body_size 32m;

    location / {
      proxy_set_header        Host $server_name;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $remote_addr;
      proxy_redirect          http:// https://;
      proxy_pass              http://Jira_upstream/;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Walt Disney, 2016-09-12
@v_sadist

Add line rewrite ^/jira(.*)$ $1 last;

server {
    listen some_ip:443;
    server_name jira.example.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example-com-new.crt;
    ssl_certificate_key /etc/nginx/ssl/example-com-new.key;
    ssl_prefer_server_ciphers On;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   

    client_max_body_size 32m;

rewrite ^/jira(.*)$ $1 last;

    location / {
      proxy_set_header        Host $server_name;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $remote_addr;
      proxy_redirect          http:// https://;
      proxy_pass              http://Jira_upstream/;
    }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question