1

I have a single Node process and it runs on 127.0.0.1:1337

I have downloaded Nginx and have only a file called nginx.conf inside conf/ directory. I am using Windows 7. There are no sites-enabled or sites-available directories as everyone say.

When I hit the url as "www.mysite.com" or "mysite", it should be pointed to the node process's IP address. But whenever I try to hit "www.mysite.com" I get the 'url not found' error from the browser. I want to redirect it to my node process , but 127.0.0.1:1337 should not be displayed in the URL bar.

How do I setup Nginx to point to my Node.js public/ folder. Should I install Node.js inside the html folder of my Nginx installation??

Whymarrh
  • 13,139
  • 14
  • 57
  • 108

2 Answers2

0

First of all, the 1337 port is a special port and shouldn't be used if you're not perfectly aware what you are doing. Various hazards could ensue from severe burnings to spontaneous body disintegration. You've been warned.

That being said, you have to run node separately as in C:\>node myserver.js and use the proxy_pass directive in nginx to proxy nginx trafic to the port your node script is listening on. Lookup nginx server_name nginx proxy_pass and simple http server in node.js in your favorite search engine.

This should get you started.

thibauts
  • 1,638
  • 9
  • 8
  • "spontaneous body disintegration"??? Are u trolling? Pls provide me with a code sample if u can. Thanks for the answer. – Vijay Britto Oct 17 '13 at 10:45
  • I'm dead serious. I gave you pointers that should allow you to solve your problems with a little search. If you want me to code it I can forward you my rates, just drop me a message. – thibauts Oct 17 '13 at 10:53
0

There is no a thing like node process IP. The IP address is an address of the network interface of your machine and the process allocates a port (at all network interfaces or at a particular one).

To achieve "hiding" the server IP address in the address bar you need to configure Windows to resolve your host name to localhost IP: How do I connect to this localhost from another computer on the same network? - this answer is too broad for your case but changing the file "hosts" is what usually enough.

Although, you cannot hide the port, unless you use default port for the HTTP protocol (which is 80).

Update: configuring the name resolution will forward the requests to the nginx process. But then nginx should forward the requests to the node.js process. Here is the sample nginx conf file:

server {
    server_name app1;

    # forwarding
    location / {
        proxy_pass http://127.0.0.1:3001;

        proxy_redirect off;

        proxy_http_version 1.1;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_read_timeout 300s;
    }
}

replace 3001 with the port of your node.js process, and app1 with your app domain.

Community
  • 1
  • 1
Alex Netkachov
  • 13,172
  • 6
  • 53
  • 85