Adding a static website

Mike Tango Bravo · Updated 2023-07-19

This section describes the steps for adding websites, following these references:

https://docs.rockylinux.org/guides/web/nginx-multisite/

https://docs.rockylinux.org/guides/security/generating_ssl_keys_lets_encrypt/

  1. Create a directory for the website HTML content.
    mkdir -p /usr/share/nginx/html/newsite.com

  2. Add default index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Site 1</title>
    </head>
    <body>
        <h1>Helo vino</h1>
    </body>
    </html>
    
  3. Change to /etc/nginx

  4. Create sites-available and sites-enabled

    mkdir /etc/nginx/sites-enabled
    mkdir /etc/nginx/sites-available
    
  5. Add sites-enabled support, by adding this line after (include /etc/nginx/conf.d/*.conf;)

    include /etc/nginx/sites-enabled/*.conf;
    
  6. Comment out the default server section

    #server {
    #    listen       80;
    #    listen       [::]:80;
    #    server_name  _;
    #    root         /usr/share/nginx/www/html;
    #
    #    # Load configuration files for the default server block.
    #    include /etc/nginx/default.d/*.conf;
    #
    #    error_page 404 /404.html;
    #    location = /404.html {
    #    }
    #
    #    error_page 500 502 503 504 /50x.html;
    #    location = /50x.html {
    #    }
    #}
    
  7. Restart the webserver

    systemctl restart nginx
    
  8. Create the website configuration file (sites-available/newsite.com.conf)

    server {
        listen 80;
        listen [::]:80;
    
        # virtual server name i.e. domain name #
        server_name site1.server.test;
    
        # document root #
        root        /usr/share/nginx/test.server.site1/html;
    
        # log files
        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
    
        # Directives to send expires headers and turn off 404 error logging. #
        location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
            access_log off; log_not_found off; expires max;
        }
    }
    
  9. Activate the site

    cd sites-enabled
    ln -s ../sites-available/martianwinefederation.org.conf
    
  10. Test everything and restart

    [sites-enabled]$ sudo nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    [sites-enabled]$ sudo systemctl restart nginx
    
  11. Add an SSL certificate with certbot

    sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email mtb@costaflores.com -d ferment.openvino.org
    
  12. Remove the section that causes loops

        #if ($host = ferment.openvino.org) {
         #   return 301 https://$host$request_uri;
        #} # managed by Certbot