different domains, pointing to Apache or Nginx, on same port
For example, example.com is for Apache, whilst static.com:8080 will go to Nginx.
This setup works great, except that some users have port 8080 blocked (such as when they are at the office), and so they cannot download the static content which makes the site unusable. I want to remove the port 8080 from my static domain, and have both servers appear to be listening on port 80.
How would I go about achieving this?
One idea I had was to (kind of) redirect static.com internally to port 8080, somewhere between the request coming in and it hitting Apache or Nginx, but after Googling around I could not find a way to achieve this.
Another solution is to take down Apache or Nginx, and have just one server, but I want to continue to use both for the same site, side by side.
I am open to any other ideas.
2 Replies
Since you have it split up by host, this could be as trivial as:
server {
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8080/;
# etc...
}
}
server {
server_name static.example.com;
root /srv/www/example.com/public_html/;
location ~ \.php$ {
rewrite ^(.*)$ http://example.com/$1 permanent;
}
location / {
# blah blah...
}
On the second blurb there, note that I stuck a redirect in there for anything ending in .php… I did it the "not quite right" way (the location block is a little redundant) to suggest that you can also combine the two and do it all on one domain! See this library article
this
For anyone else finding this post, after a similar solution, I have setup my nginx to forward everything on to apache, in nginx.conf. This way if I add more sites to apache, they should 'just work'.
This is what my my default server settings in nginx.conf looks like:
server {
# the IP of my Linode box
# if you use this, change it to yours
listen 192.168.1.67:80;
location / {
proxy_pass http://127.0.0.1; # redirect to apache
proxy_redirect off;
proxy_buffering off;
# needed to prevent some apache redirects to localhost
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}