Scenario#
I want to set up a simple website on a server, with the local path as /www/website
, and map it to my own domain example.com
.
Configuration#
The main configuration file for Nginx is located at /etc/nginx/nginx.conf
or /etc/nginx/conf/nginx.conf
.
Create a configuration file, usually with a .conf
extension, and by default map to port 80.
http {
...
server {
listen 80; #Port number
server_name example.com; #Domain to map
location / {
root /www/website; #Specify the local path of the page, note that it must start with '/'
index index.html; #Default index
}
}
...
}
If configuring an SSL certificate, add port 443:
http {
...
server {
listen 443 ssl; #Port number
server_name example.com; #Domain to map
ssl_certificate /path/to/your/certificate.crt; #SSL certificate path
ssl_certificate_key /path/to/your/private.key; #SSL certificate key path
location / {
root /www/website; #Specify the local path of the page, note that it must start with '/'
index index.html; #Default index
}
}
...
}
Save and Reload#
Execute the following command to save and reload the nginx settings:
sudo systemctl reload nginx