node.js & nginx proxy set up -- something is wrong, but what? - node.js

So I used this stackoverflow answer to try and set up my local (on osx) nginx server to have my node.js site that is getting successfully published to 127.0.0.1:3000 to appear at my_url.org in my browser. It isn't working.
Here is my nginx server: I've tried this both in the nginx.conf file directly and as a separate file which I created in the sites-available folder and then created the link to the sites-enabled folder (per the answer linked above)
upstream app_name {
server 127.0.0.1:3000;
keepalive 8;
}
server {
listen 0.0.0.0:80;
server_name my_url.org my_url;
access_log /usr/local/var/log/nginx/my_url.org.log;
location / {
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_pass http://app_name/;
proxy_redirect off;
}
}
Some clues:
I know the node is working because I can see the code at 127.0.0.1:3000
I know the nginx.conf file is set up correctly because: sudo nginx -t tells me so and I have a seperate server within the nginx.conf file coming through correctly on port 8080.
So far any error logs are blank or non-existent.
when I go to my_url.org I see the remote server on which the site is hosted. Not 127.0.0.1:3000.
after every change I sudo nginx -s reload.
I've tried both listen 80; and listen 0.0.0.0:80 with equal lack of success.
When I try this with the above code in the linked sites-enabled folder, I have the line include /usr/local/etc/nginx/sites-enabled/*; in the nginx.conf file. When I have the above code in the nginx.conf file, I comment that line out.
I'm assuming I'm missing something obvious but missing it I am. Any help wildly appreciated.

You should have to point my_url.org to 127.0.0.1 in your hosts file (with linux and linux-like it should be in /etc/hosts).
Otherwise your browser won't know to redirect to your local server.
(I answered in a comment, moving down here for future devs with same problem.)

Related

404 not found, nginx looking for the default path 'etc/nginx/html/index.html' on NextJS application

I'm currently in need of some help with this 404 issue I've been stuck on for days now. My system is running CentOS7 (CPanel, VPS) and it uses engintron for the nginx reverse proxy and pm2 to keep my next.js application running.
default.conf
server {
#listen 80 default_server;
listen 80;
server_name my.domain.name domain.name;
location / {
# reverse proxy for next server
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /_next/static/ {
alias path/to/nextjs/static/folder;
expires 365d;
access_log off;
}
# deny all; # DO NOT REMOVE OR CHANGE THIS LINE - Used when Engintron is disabled to block Nginx from becoming an open proxy
# Set the port for HTTP proxying
set $PROXY_TO_PORT 8080;
include common_http.conf;
}
All the other files I haven't touched, so it's safe to rule them out as they're the default ones that come with engintron.
Connecting to my.domain.name, gives me this error in the console.
"/etc/nginx/html/index.html" is not found (2: No such file or directory), client: ::ffff:my.ip.address, server: my.domain.name, request: "GET / HTTP/2.0", host: "my.domain.name"
My best guess on why this problem occurs is because my domain/server can't receive the files or doesn't have permission through the proxy at all as getting the data at 127.0.0.1:3000 via curl http://127.0.0.1/3000 returns my site's code in full.
Any ideas on what could be causing this? Have an amazing rest of your day :)
Engintron can make proxying to Node apps easy. Have a look at the docs (engintron.com/docs) as well as the "custom rules" files in WHM > Plugins > Engintron.
As long as you load your Node site in your public_html folder for the given account (Apache cannot render it either way, so it's not an issue) and _next/static/ is inside that public_html folder (for symmetrical proxying), then the Node.js proxy rule you set in Engintron's custom rules (again see the docs) will be sufficient for your needs.
I would also recommend you revert any changes you did in Engintron's Nginx config files.

Ngnix and forwarding requests to a port

I have a node application running at mydomain.com:1234. It's working and loads just fine. However, when I try to use nginx to forward 80, my connection is refused. My setting is sites-available looks like this:
server {
listen 80;
server_name mydomain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_pass http://127.0.0.1:1234;
}
}
So the problem wasn't something that could easily be seen from this question. If you create your symlink with from inside the nginx directory and use
ln -s sites-available/mysite sites-enabled/mysite
Everything will look ok. However, since you used a relative path, the link is all messed up and won't ever load your config. Instead you just have to use
ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/mysite
and then everything works like gangbusters.

Nginx proxy config problems for Node.js app

I'm almost certain this is just my ignorance and expecting this to be an easy fix, but basically mydomain.com:3000 serves the correct content, but mydomain.com does not. Here is what my nginx.conf.default file has:
upstream mydomain {
server 127.0.0.1:3000;
keepalive 8;
}
server {
listen 0.0.0.0:80;
server_name mydomain.com www.mydomain.com;
location / {
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_pass http://mydomain/;
proxy_redirect off;
}
}
I've been following this article, but can't figure out where my error is:
http://dailyjs.com/2010/03/15/hosting-nodejs-apps/
(Note: I believe my installation of nginx differs from this as there is no sites-available folder. Instead, I'm editing the nginx.conf.default file because I saw the lines for the localhost server above the ones I've got here.)
Basically, what I want is to be able to visit mydomain.com to load the content, instead of mydomain.com:3000.
This is all a matter of distros and packages not nginx versions, I've explained this in a different answer before, the main and the only file that matters is nginx.conf, if you check that file you would know what folders matters and what don't, for example debian distros add this line in their config
include /etc/nginx/sites-enabled/*;
So that auto includes all the files inside the sites-enabled folder,
Redhat distros use this line only
include /etc/nginx/conf.d/*.conf;
which is btw still also included in the debian distributed config,
This means that only the files inside /etc/nginx/conf.d are considered, and also they have to end with .conf
Just check your nginx.conf and make sure that your config is in an included folder, as for the config it self it seems that it should be working fine.
With the newer installation of NginX, there is a subfolder called vhosts. Virtual Host config data needs to go in this folder. If you add a domain to cPanel using the UI, it creates a vhost file automatically.

NGINX dns is not working on VPS

I'm a little new to VPS/Linux so please bear with me.
I have a domain name (attendahh.com) pointed to my host's nameservers.
I've set up /etc/nginx/conf.d/attendahh.com.conf as follows:
# the IP(s) on which your node server is running. I chose port 3000.
upstream attendahh.com {
server 127.0.0.1:1999;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name attendahh.com attendahh;
access_log /var/log/nginx/attendahh.log;
# pass the request to the node.js server with the correct headers and much $
location / {
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_pass http://attendahh.com/;
proxy_redirect off;
}
}
Then I service nginx restart.
I've read a bunch of tutorials and stack answers this is ostensibly all I need to do, but if I go to http://attendahh.com it does not work.
Things to note:
Going to my IP + port in the browser works just fine ( 23.226.227.16:1999 )
I have Cpanel for VPS installed (I tried to set up the DNS in there originally but it didn't work, I've since deleted the dns entry from there but it may still be affecting things)
Apache virtual hosts are commented out in httpd.config.
Any ideas on what I'm doing wrong here? Perhaps there's some conflict between apache and nginx?
- proxy_pass http://attendahh.com/;
+ proxy_pass http://attendahh.com;
Nginx uses its own resolver, it doesn't use the system's resolver (/etc/resolver).
You have to configure it using the resolver directive. If you are not using the resolver directive, then use IP address in the proxy_pass directive.
Source: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

Subdomain problems using nginx as a reverse proxy for node apps

I am new to nginx and I'm struggling to get my configuration for a reverse proxy working. I have a node app running on localhost:3010 and I'm trying to serve pages through nginx from this app at the subdomain dev.[sitename].org. Let's just say dev.example.org for readability. Here are the contents of a file I created in sites-available called example.org (is that the correct name for this file?):
server {
server_name www.example.org example.org;
}
upstream app_dev.example.org {
server 127.0.0.1:3010;
}
server {
listen 0.0.0.0:80;
server_name dev.example.org;
access_log /var/log/nginx/dev.example.access.log;
location / {
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_pass http://app_dev.example.org/;
proxy_redirect off;
}
}
This is mostly based off this related question: Node.js + Nginx - What now? however when I try to open dev.example.org in my browser, Chrome reports that it can't find the page. I can ping dev.example.org and get an IP address, so the server seems to be available, but my nginx configuration incorrect. I created the symlink in sites-enabled and restarted nginx, in case you thought I might have forgotten those steps.
So my thought now is that I'm not referring to the subdomain correctly somewhere, or maybe my file in sites-available is named wrong. Any push in the right direction would be appreciated.
Just to be sure the problem is on nginx try these steps:
Set a test server at port 3030, serving the system doc folder or anything else.
server {
listen 3030
location / {
root /usr/share/doc/;
autoindex on;
}
}
upstream simple_test {
server 127.0.0.1:3030
}
Then use simple_test below as well:
proxy_pass http://simple_test/;
If you see the /usr/share/doc dir listing when you access dev.example.org then your issue is on the node side.
Turned out something was blocking port 80! fixed that and the config as posted above worked

Resources