How to Serve Your Static Website with Nginx on Alpine Linux

You can place your static website files in the directory that Nginx serves by default. For Alpine Linux, this is typically /var/www/localhost/htdocs.

Here’s a step-by-step guide to setting it up:

1. Copy Your Static Website Files

Copy your static website files to the /var/www/localhost/htdocs directory:

cp -r /path/to/your/static/website/* /var/www/localhost/htdocs/

2. Adjust Permissions

Ensure Nginx can read the files by adjusting the permissions:

chown -R nginx:nginx /var/www/localhost/htdocs/

3. Verify Nginx Configuration

Ensure Nginx is serving files from the correct directory. Check the /etc/nginx/nginx.conf file or the specific site configuration file in /etc/nginx/http.d/.

The default server block in nginx.conf should look something like this:

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /var/www/localhost/htdocs;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /40x.html {
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }
}

4. Restart Nginx

Restart Nginx to apply the changes:

rc-service nginx restart

Now, if you open your browser and navigate to your server’s IP address or domain name, you should see your static website.


Chuck Norris Joke: When Chuck Norris configures Nginx, the server doesn’t need to serve static files. The files serve themselves out of respect.


Related Posts