0

I'm trying to expose one part of my web server via one address, and another part via another. I feel like my use case should be simple, but nginx is giving me a lot of troubles.

What I currently have is this:

Server one:

server {
  listen 443 ssl;
  server_name mydomain.com;

  location /dev/subfolder {
    proxy_pass http://dev.mydomain.local/subfolder;
    proxy_redirect http:// https://;
  }
}

Server two:

server {
  listen 80;
  server_name dev.mydomain.com;

  location /main {
    #some config
  }
  location /subfolder {
    return 404;
  }
}
server {
  listen 80;
  server_name dev.mydomain.local;

  location /subfolder {
    #some config
  }
}

The problem is, if I add a proxy_set_header Host $host directive to server one, the first server block on server two will pick up the request, and return 404. If I don't include that header, my browser will try to navigate to dev.mydomain.local and fail, because that domain is only available internally. How do I fix this problem?

  • sounds like when it hits dev.mydomain.local its returning like a 301/302 redirect.. can you run something like curl -v mydomain.com and paste the results from the same machine as your browser? – Mike Mar 2 '15 at 14:15
  • @Mike Sure, here you go: pastebin.com/kkw4ac6V – Jorn Mar 2 '15 at 15:17
  • so now you can run curl -v mydomain.com/dev/subfolder/ – Mike Mar 2 '15 at 18:42
  • Post your full configuration on both servers. – Xavier Lucas Mar 3 '15 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.