Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm totally new to nginx.

I want to forward two subdomains to the two applications in my apache tomcat server.

As I searched over internet, I found that rewrite does the forwarding but I cannot see forwarding. As I see from the logs, it gets into an infinite loop.

Here is my server configuration

http {
     upstream tomcat {
       server tomcat.ip.address:8080;
      }
      server {
        listen 80;
        server_name  sub1.domain.com;
        location / {
            proxy_pass    http://tomcat/app1
            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_redirect http://tomcat/app1 http://sub1.domain.com;
            proxy_buffering off;
            proxy_store     off;

        }
      }
      server {
        listen 80;
        server_name  sub2.domain.com;
        location / {
            proxy_pass    http://tomcat/demo;
            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_redirect http://tomcat/demo http://sub2.domain.com;
            proxy_buffering off;
            proxy_store     off;
        }
      }
}

Whenever I invoke sub1.domain.com or sub2.domain.com, I'm get the message that there is a redirection loop problem and it's invalid?

So, How can I fix this problem?

share|improve this question

migrated from stackoverflow.com Nov 2 '12 at 10:23

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

Here is right way to do it. Hope it would be helpful:

https://wiki.duraspace.org/display/DSPACE/NginX+Tomcat+Proxying

share|improve this answer
    
it's not exactly what I want. But I tried it, still it doesn't work for me. I'm using tomcat 7 and nginx 1.2.4 stable. –  erdimeola Nov 2 '12 at 11:30
add comment

I'll try this:

http{
  upstream tomcat {
    tomcat.ip:8080;
  }
  server {
    listen 80;
    server_name  subdomain1.domain.com;
    location / {
      proxy_pass    http://tomcat/app1;
    }
  }
  server {
    listen 80;
    server_name  subdomain2.domain.com;
    location / {
      proxy_pass    http://tomcat/app2;
    }
  }
  ....

Look at nginx doc.

share|improve this answer
    
I've tried this @undx. it still shows the welcome screen. Can you let me know if it works for you? –  erdimeola Nov 2 '12 at 11:40
    
stupid question but did you restart nginx ? And another question : What the nginx logs are saying ? –  undx Nov 2 '12 at 11:52
    
I've restarted it. I added the server keyword before tomcat.ip:8080. problem is whenever I invoke subdomain1.domain.com , it says that the forwarding is invalid –  erdimeola Nov 2 '12 at 12:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.