5

I have an nginx on port 80 and a tomcat on port 8080 configured as upstream.

The war application in tomcat listen to /pwm.

I would like to configure nginx to a reverse proxy for tomcat and rewrite the url "/" to "/pwm".

example: user types "web.noc.local" in browser and nginx rewrites the url to web.noc.local/pwm and redirects to tomcat on port 8080.

my nginx config:

upstream pwm_server  {
    server 127.0.0.1:8080 fail_timeout=0;
}

server {
    listen       80;
    server_name  web.noc.local;     
    access_log  /var/log/nginx/log/web.noc.local.access.log  main;
    error_log  /var/log/nginx/log/web.noc.local.error.log;      
    location / {
        if ($is_args != "") {  
            rewrite "^$" /pwm  break;
            expires     7d;
            proxy_pass http://pwm_server; 
        }           
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;    
        proxy_max_temp_file_size 0;     
        proxy_buffering off;
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        proxy_read_timeout 30;
        proxy_pass http://pwm_server;
    }
}

now when I open the url the, nothing happens, only a blank screen.

thx for help.

1 Answer 1

4

Ok, I found a solution for me:

location / {
    rewrite ^ http://web.noc.local/pwm/ last;
}

location /pwm {

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;

    proxy_max_temp_file_size 0;     
    proxy_buffering off;
    proxy_connect_timeout 30;
    proxy_send_timeout 30;
    proxy_read_timeout 30;
    proxy_pass http://pwm_server;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.