Hello,
So I’m a new user here, and am following this tutorial closely: https://www.digitalocean.com/community/tutorials/how-to-manage-front-end-javascript-and-css-dependencies-with-bower-on-ubuntu-14-04#step-6-—-creating-a-hello-world-application
I managed to get all the way down to Step 6, where I create a new application. I figured I would do this by modifying the index.html file. However, once I have done that, my web page still displays the default nginx message! I even tried to restart the entire server as well as nginx. Does anyone know what could be the problem? Thanks!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
When it comes to NGINX and NodeJS, you’ll need to configure your NGINX server block to proxy to your NodeJS application.
By default, NGINX listens on Port 80 – most NodeJS applications listen on ports such as 3000 or the port that your application is configured to listen on. The reason for this is security – you don’t want a NodeJS application running as root, which would be required in most cases if you wanted to run it on port 80 instead of NGINX.
…
When you install NGINX, a default server block is created here:
/etc/nginx/sites-available/default
What you’d want to do is wipe that file clean.
truncate -s 0 /etc/nginx/sites-available/default
Then open it up:
nano /etc/nginx/sites-available/default
Inside of that file, you’d want to paste your modified version of this:
upstream @backend {
server 127.0.0.1:3000;
}
server
{
listen 80;
listen [::]:80;
server_name domain.com www.domain.com;
location /
{
proxy_pass http://@backend;
proxy_buffers 16 32k;
proxy_buffer_size 64k;
proxy_busy_buffers_size 128k;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_connect_timeout 59s;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_ignore_headers Cache-Control Expires;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
proxy_no_cache $http_pragma $http_authorization;
proxy_pass_header Set-Cookie;
proxy_read_timeout 600;
proxy_redirect off;
proxy_send_timeout 600;
proxy_temp_file_write_size 64k;
proxy_set_header Accept-Encoding '';
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header Proxy '';
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Original-Request $request_uri;
}
}
In the above, you’d want to change server 127.0.0.1:3000; to match your NodeJS port (i.e. change 3000 to your port). You’d also want to make sure your NodeJS application is running from localhost using 127.0.0.1 as the IP.
You’ll also want to change server_name domain.com www.domain.com; to match your domain.
You’d then save the file and restart NGINX using:
service nginx restart
…
The above sets NGINX up as a Reverse Proxy, which is what we need in order to keep the port out of the URL. Without NGINX, or a web server in general, you’d have to listen on a public IP and add the port to your URL.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.