2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NGINX https index.html configuration

Last updated at Posted at 2024-10-14

These instructions should work for a Debian GNU/Linux
NGINX is an http server listening by default on port 80 (http)
Would you like to setup your host to accept SSL/TSL calls on port 443 (https)

https://mywebsite.com

You should have "let's encrypt" certificate files:

/etc/letsencrypt/live/mywebsite.com/fullchain.pem
/etc/letsencrypt/live/mywebsite.com/privkey.pem

To install nginx with Linux bash command

sudo apt install nginx

to start and stop and verify http server

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl status nginx

check the server is running as www-data process.
You should find this line in /etc/nginx/nginx.conf

user www-data;

to verify your port 80 is binding with nginx

sudo netstat -plnt

your http index directory sohoud go into /var/www/

sudo mkdir /var/www/mywebsite.com
sudo chown www-data /var/www/mywebsite.com
sudo chgrp www-data /var/www/mywebsite.com
sudo chmod 775 /var/www/mywebsite.com

create a new file for website configuration in /etc/nginx/sites-available/

sudo vi /etc/nginx/sites-available/mywebsite.com

copy this configuration as the content

server {
  root /var/www/mywebsite.com;
  server_name *.mywebsite.com;
  keepalive_timeout 70;
  ssl_session_tickets on;

  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;

  index index.html;
}

server {
    return 301 https://$host$request_uri;

    listen 80;
    listen [::]:80;
    server_name *.mywebsite.com www.mywebsite.com mywebsite.com;
    return 404; # managed by Certbot
}

create a symbolic link in /etc/nginx/sites-enabled

  cd /etc/nginx/sites-enabled
  sudo ln -s /etc/nginx/sites-available/mywebsite.com mywebsite.com

include your username (i.e. bob) into www-data group

  usermod -a -G www-data bob

create an index file

  echo "it works!" > /var/www/mywebsite.com/index.html

restart nginx http server

sudo systemctl restart nginx

make the test, open your browser and type your website url:

   https://mywebsite.com
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?