0

I have a CentOS VPS, running Apache. Previously I just used it for hosting a bunch of PHP and static HTML websites, under various domains, and everything worked fine.

Then I developed a simple Node.js app. I published it on my VPS, and it was accessible, if I put :3000 after my IP.

I did some research into how to make my Node app accessible under it's new domain name, while keeping the Apache config similar to how it is. The solution seems to be reverse proxying with Nginx.

Ultimately what I want is:

  • All my old sites that are PHP and HTML apps, and are running on Apache, to still be accessible under there usual domains, on Apache (port :8081)
  • My Node app (running on port :3000) to be accessible just through it's new domain name, without a port number required

What I currently have:

nginx.conf

  user  asykes;

  error_log  /var/log/nginx/error.log warn;
  worker_rlimit_nofile 20480;

  events {
    worker_connections 5120; # increase for busier servers
    use epoll; # you should use epoll here for Linux kernels 2.6.x
  }


  http{
    include "/etc/nginx/sites-enabled/*";
  }

And for my Node app config, sites-available/sentiment-sweep.conf (with symlink to site-enabled)

server {
  listen 80;
  server_name sentiment-sweep.com;

  location / {
      proxy_pass http://localhost:3000;
  }
}

What this currently does

All domains on my server all resolve to my node app which is on port 3000

I need only http://sentiment-sweep.com/ to resolve to localhost:3000, and everything else to go to their Apache version on revisionquizzes.co.uk:8081/ and http://computerscience.as93.net:8081/ and so on...

I have spent hours playing around with nginx config, adding server{location{}} for the Apache port, but seem to be getting nowhere. The closest I got, was when it rendered the Apache Sorry page.

Any suggestions or help would be so much appreciated, thanks in advance

Alicia
  • 183
  • 1
  • 6
  • Look at the top right of the page. See the search box - you should use it. This will almost certainly have been asked and answered here before. Start with this [search](http://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite) – user9517 Mar 12 '16 at 09:33

1 Answers1

0

You must specify the location where it should be proxied. Assuming your domain name is http://example.com.

See the route of the url when you access them below.

http://example.com --> http://localhost:3000
http://example.com/revisionquizzes --> revisionquizzes.co.uk:8081
http://example.com/computerscience  --> http://computerscience.as93.net:8081

Sample config only, just define the location in your nginx config:

server {
  listen 80;
  server_name default_server;

  location / {
      proxy_pass http://localhost:3000;
  }

  location /revisionquizzes {
      proxy_pass revisionquizzes.co.uk:8081;
  }

  location /computerscience {
      proxy_pass http://computerscience.as93.net:8081;
  }

}