Web Page Not Updating

May 20, 2017 344 views
Caching Ubuntu Ubuntu 16.04

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!

1 Answer

@alex44sport

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.

Have another answer? Share your knowledge.