This repository demonstrates a simple Nginx configuration to serve a static website. It contains three interlinked HTML pages and an Nginx configuration file.
index.html
: The homepage of the site.contact.html
: The contact page.about.html
: The about page.nginx.conf
: Nginx configuration file to set up the server.
Ensure you have the following:
- Nginx installed on your system.
- Access to the Nginx configuration directory (usually
/etc/nginx/
). - Proper permissions to edit files and restart the Nginx service.
- Copy the
index.html
,contact.html
, andabout.html
files to your web root directory. For most systems, this is/var/www/html/
. Use the following command:sudo cp index.html contact.html about.html /var/www/html/
- Set appropriate permissions so that Nginx can serve the files:
sudo chmod 644 /var/www/html/index.html /var/www/html/contact.html /var/www/html/about.html
- Copy the
nginx.conf
file to the Nginx configuration directory:sudo cp nginx.conf /etc/nginx/sites-available/nginx-demo
- Create a symbolic link in the
sites-enabled
directory:sudo ln -s /etc/nginx/sites-available/nginx-demo /etc/nginx/sites-enabled/
- Test the Nginx configuration:
If there are no errors, proceed to the next step.
sudo nginx -t
- Restart Nginx to apply the configuration:
sudo systemctl restart nginx
- Open your browser and visit
http://localhost/
to view the homepage. - Test navigation to the
about.html
andcontact.html
pages via the links on the homepage.
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
- The three pages (
index.html
,contact.html
,about.html
) are interlinked. Make sure all files are in the same directory specified in theroot
directive of the Nginx configuration. - Use
sudo
if your user does not have direct permissions for the Nginx directories.
This is a basic setup. You can enhance it by:
- Adding SSL/TLS for secure connections.
- Setting up a custom 404 page.
- Configuring Nginx to serve dynamic content using a backend like PHP or Node.js.
Happy learning with Nginx! If you encounter any issues, feel free to open a discussion or raise an issue in this repository.