Question

Ubuntu Server 14.04 LTS. I'm running WordPress as a standard install, i.e in /var/www/html. I also have a Discourse instance running in a Docker container, with port 8081 exposed. My intention is to have the WP instance at domain.com and Discourse on sub.domain.com. I've tried using nginx to intercept requests for sub.domain.com but it doesn't seem to be working - it just sends everything to domain.com. What have I done wrong?

/etc/nginx/sites-enabled/sub.domain.com:

server {
  listen 80;
  server_name sub.domain.com;

  location / {
    proxy_pass http://localhost:8081;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  }
}
Was it helpful?

Solution

Try the following:

server {
  listen 80;
  server_name sub.domain.com;

  location / {
    proxy_pass http://127.0.0.1:8081;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  }
}

localhost may not necessarily resolve to 127.0.0.1 which is where your Docker container is listening.

Make sure you can get to port 8081 from your machine. Run:

$ telnet 127.0.0.1 8081
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top