Nginx : The Doc Is Ready

This commit is contained in:
2024-11-07 16:06:11 +03:30
parent f0b240989a
commit 35314b827f
7 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
# Nginx Documentation
## What Is Nginx?
**Nginx** (pronounced "engine-x") is a popular open-source web server and reverse proxy software. Known for its high performance, stability, rich feature set, simple configuration, and low resource consumption, Nginx has become one of the most widely used server applications worldwide.
Originally developed by Igor Sysoev, Nginx was designed to address the **C10k problem**—the challenge of handling 10,000 concurrent client connections. Nginx overcomes this limitation through an **event-driven, asynchronous architecture** that enables it to manage a vast number of simultaneous connections efficiently and with minimal resource usage.
---
## Key Features of Nginx
1. **High Performance**: Nginx is optimized to handle high-traffic websites and can serve static content faster than many other web servers.
2. **Stability**: Its design enables stable operation under heavy load, making it reliable for production environments.
3. **Low Resource Consumption**: The asynchronous architecture minimizes memory and CPU usage, making it suitable for high-concurrency environments.
4. **Flexibility**: Nginx can be easily configured to function as a web server, reverse proxy, load balancer, and more.
5. **Security**: Nginx supports SSL/TLS and can be configured for secure HTTPS connections, with built-in features to prevent DoS and DDoS attacks.
6. **Extensibility**: Through a range of modules, Nginx can be extended to support various functions such as caching, load balancing, access control, and more.
---
## Common Uses of Nginx
Nginxs versatility makes it a powerful tool for a wide range of applications. Below are some of its most common uses:
### 1. Web Server
Nginx can serve as a **standalone web server** to deliver static content like HTML files, images, videos, and more. Due to its efficiency, its commonly used to serve content directly or in front of other server applications for added performance and caching benefits.
### 2. Reverse Proxy
Acting as a **reverse proxy**, Nginx can forward client requests to another server, often used to route traffic to applications hosted on multiple servers. This approach helps manage and distribute incoming traffic, improving performance and security by hiding the backend server details from clients.
### 3. Load Balancer
Nginxs **load balancing** capabilities help distribute traffic across multiple servers. Load balancing not only increases fault tolerance by rerouting traffic in case of server failure but also enhances performance by preventing any single server from becoming overloaded.
Common load balancing methods in Nginx:
- **Round Robin**: Distributes requests sequentially across servers.
- **Least Connections**: Routes traffic to the server with the fewest active connections.
- **IP Hash**: Ensures clients are consistently routed to the same server based on their IP address.
### 4. Caching
Nginx can act as a **caching server** to store copies of frequently requested content. By serving cached content, Nginx can significantly reduce load times for users and lessen the workload on backend servers. This is especially beneficial for high-traffic websites with dynamic content.
---
## Additional Nginx Features
- **SSL/TLS Termination**: Nginx can terminate SSL/TLS connections, handling the encryption and decryption process to reduce the burden on backend servers.
- **URL Rewriting and Redirection**: With URL rewriting rules, Nginx can redirect requests to different URLs, enabling efficient handling of routing and user-friendly URLs.
- **Access Control**: Provides robust tools for managing access controls, including IP-based access restrictions, user authentication, and authorization.
- **HTTP/2 and HTTP/3 Support**: Supports newer HTTP protocols for faster and more secure connections.
- **Customizable Modules**: Nginxs modular architecture allows for custom modules, enabling functionality for a wide range of applications and configurations.
---

View File

@@ -0,0 +1,114 @@
# Installing Nginx
## Prerequisites
Before installing Nginx, ensure that you have root or sudo privileges on your system to carry out installation and configuration commands.
## Step-by-Step Installation
### For Debian-Based Systems (e.g., Ubuntu)
1. **Update Package Repositories**
Its a good practice to update your package repositories before installing new software to ensure youre downloading the latest version available.
```bash
sudo apt update
```
2. **Install Nginx**
Install Nginx from the package repository.
```bash
sudo apt install nginx
```
3. **Start Nginx Service**
Once installed, start the Nginx service.
```bash
sudo systemctl start nginx
```
4. **Enable Nginx to Start on Boot**
This command configures Nginx to start automatically whenever the server reboots.
```bash
sudo systemctl enable nginx
```
5. **Check Status (Optional)**
Verify that Nginx is running correctly.
```bash
sudo systemctl status nginx
```
### For Red Hat-Based Systems (e.g., CentOS, Fedora)
1. **Update Package Repositories**
As with Debian-based systems, its recommended to update repositories first.
```bash
sudo yum update
```
2. **Install Nginx**
On Red Hat-based systems, install Nginx with `yum`.
```bash
sudo yum install nginx
```
3. **Start Nginx Service**
Start Nginx after installation.
```bash
sudo systemctl start nginx
```
4. **Enable Nginx to Start on Boot**
Configure Nginx to launch automatically on system startup.
```bash
sudo systemctl enable nginx
```
5. **Check Status (Optional)**
Confirm that Nginx is running and functioning properly.
```bash
sudo systemctl status nginx
```
---
## Post-Installation Steps
1. **Allow Nginx Through the Firewall**
If your server has a firewall enabled, you may need to allow HTTP (port 80) and HTTPS (port 443) traffic.
### Debian-Based Systems:
```bash
sudo ufw allow 'Nginx Full'
```
### Red Hat-Based Systems:
```bash
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
```
2. **Verify Installation**
Open a web browser and navigate to your servers IP address or domain name:
```
http://<your-server-ip>
```
You should see the default Nginx welcome page, which confirms that the installation is successful.
---
## Troubleshooting Common Installation Issues
- **Error: Package Not Found**
If you encounter an error stating that the Nginx package was not found, you may need to install the **EPEL repository** (Extra Packages for Enterprise Linux) on Red Hat-based systems:
```bash
sudo yum install epel-release
sudo yum install nginx
```
- **Permission Denied Errors**
Ensure youre using `sudo` to run commands that require root privileges.
- **Firewall Blocking Access**
If you cant access Nginx via a browser, ensure that firewall rules are configured to allow HTTP/HTTPS traffic.

View File

@@ -0,0 +1,155 @@
# Setting Up a Web Server on Nginx
This guide covers the steps to configure Nginx as a basic web server to serve static HTML files and handle HTTP requests. We'll set up a sample web server on a Debian-based system, but the steps are similar for other Linux distributions.
---
## Prerequisites
- A server with **Nginx installed**. If you havent installed Nginx yet, follow the installation instructions in the [Nginx Installation Guide](2-Installtion.md) (or use the provided installation commands).
- **Root or sudo privileges** to edit configuration files and restart Nginx services.
---
## Step 1: Set Up the Web Directory
1. **Create a Directory for Your Website**
Nginx typically serves content from `/var/www/`. Create a new directory for your website content.
```bash
sudo mkdir -p /var/www/example.com/html
```
2. **Set Permissions**
Ensure that the Nginx user (usually `www-data`) has permission to read files in this directory.
```bash
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com
```
3. **Add a Sample HTML File**
Create a simple HTML file to confirm the setup.
```bash
echo "<html>
<head>
<title>Welcome to Example.com!</title>
</head>
<body>
<h1>Success! Nginx is serving your website.</h1>
</body>
</html>" | sudo tee /var/www/example.com/html/index.html
```
---
## Step 2: Configure Nginx to Serve the Website
1. **Create a Server Block Configuration File**
Nginx server blocks (similar to Apache virtual hosts) allow you to host multiple sites on the same server. Create a new configuration file for your site.
```bash
sudo vim /etc/nginx/sites-available/example.com
```
2. **Add Server Block Configuration**
Paste the following configuration into the file, replacing `example.com` with your domain or IP address:
```nginx
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
```
3. **Enable the Server Block**
Link the configuration file to `sites-enabled` to enable it in Nginx:
```bash
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
```
4. **Test the Nginx Configuration**
Run the following command to check for any syntax errors in the configuration:
```bash
sudo nginx -t
```
5. **Reload Nginx to Apply Changes**
If the syntax test passes, reload Nginx to apply the new configuration.
```bash
sudo systemctl reload nginx
```
---
## Step 3: Configure DNS (Optional)
If you have a domain name, point it to your servers IP address in your DNS providers settings. Create an A record for `example.com` and, if desired, `www.example.com` to direct traffic to your servers IP address.
---
## Step 4: Access Your Website
In a web browser, navigate to `http://example.com` (replace `example.com` with your domain or IP address). You should see the sample HTML page you created, confirming that Nginx is serving your web content.
---
## Optional: Enabling HTTPS with SSL/TLS
For added security, you can configure HTTPS on your Nginx web server. One free and easy way to do this is by using **Lets Encrypt**.
1. **Install Certbot and the Nginx Plugin**
```bash
sudo apt install certbot python3-certbot-nginx
```
2. **Obtain and Install a Certificate**
Run the following Certbot command to automatically obtain and configure an SSL certificate for your website:
```bash
sudo certbot --nginx -d example.com -d www.example.com
```
3. **Verify Renewal Process**
Certificates from Lets Encrypt expire every 90 days. To automatically renew the certificates, add a cron job or use Certbots built-in renewal service:
```bash
sudo certbot renew --dry-run
```
Now your website will be accessible securely at `https://example.com`.
---
## Nginx Configuration Summary
Here's a quick reference for the key commands and file paths:
- **Site root directory**: `/var/www/example.com/html`
- **Nginx configuration files**:
- Site-specific: `/etc/nginx/sites-available/example.com`
- Enabled sites: `/etc/nginx/sites-enabled/`
- **Commands**:
- Check configuration syntax: `sudo nginx -t`
- Reload Nginx: `sudo systemctl reload nginx`
---
## Troubleshooting Common Issues
1. **Error: 403 Forbidden**
- Check that Nginx has the necessary permissions to access files in the root directory (`/var/www/example.com/html`). Use `chmod 755` and `chown` commands as shown above.
2. **Error: 404 Not Found**
- Ensure the `index.html` file exists in the specified directory and that `try_files` directive is correctly pointing to it.
3. **Configuration Errors**
- Always run `sudo nginx -t` to check configuration changes before reloading Nginx.
4. **SSL Issues**
- If HTTPS fails, make sure Certbot successfully installed the certificate and that the DNS settings correctly point to your servers IP address.
---

View File

@@ -0,0 +1,108 @@
# Setting Up a Reverse Proxy with Nginx
A reverse proxy can forward client requests to multiple backend servers, helping manage traffic, load balance, and secure the backend infrastructure. This guide provides a step-by-step approach to setting up a basic reverse proxy configuration in Nginx.
---
## Prerequisites
- **Nginx Installed**: Ensure that Nginx is installed and running on your server.
- **Root or sudo privileges** to edit configuration files and restart Nginx.
- **Backend Servers**: At least two backend services or applications you want to proxy, such as `http://web1.com` and `http://web2.com`.
---
## Step 1: Create the Reverse Proxy Configuration File
1. **Open a new configuration file** for your reverse proxy in Nginx's `sites-available` directory:
```bash
sudo vim /etc/nginx/sites-available/reverse-proxy.conf
```
2. **Define the Reverse Proxy Configuration**
Copy the following configuration into the file. Adjust the backend server names (`web1.com` and `web2.com`) to match your actual server addresses.
```nginx
server {
listen 80;
server_name _; # Use "_" to accept any hostname, or specify a domain name
# Proxy for the first backend application
location /web1 {
proxy_pass http://web1.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Proxy for the second backend application
location /web2 {
proxy_pass http://web2.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Log settings
access_log /var/log/nginx/reverse-proxy-access.log;
error_log /var/log/nginx/reverse-proxy-error.log;
}
```
### Explanation of Key Directives
- **listen**: Specifies the port Nginx will listen on (80 for HTTP).
- **server_name**: The domain name or IP address for this reverse proxy. Using `_` allows it to accept any hostname.
- **location**: Defines the URL path (`/web1`, `/web2`) to route to different backend servers.
- **proxy_pass**: Specifies the backend server URL to which traffic should be forwarded.
- **proxy_set_header**: Sets headers that pass client information to the backend, preserving the original IP and protocol.
- **access_log**: Logs access requests.
- **error_log**: Logs error messages for easier troubleshooting.
---
## Step 2: Enable the Reverse Proxy Configuration
1. **Create a symbolic link** from `sites-available` to `sites-enabled` to enable the reverse proxy configuration in Nginx:
```bash
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
```
2. **Verify Nginx Configuration**
Run a configuration test to ensure there are no syntax errors:
```bash
sudo nginx -t
```
3. **Reload Nginx** to apply the changes:
```bash
nginx -s reload
```
---
## Step 3: Access Your Reverse Proxy
With the reverse proxy set up, you can now access your backend services using the following URLs:
- **http://your-server-ip/web1**: For requests proxied to `http://web1.com`
- **http://your-server-ip/web2**: For requests proxied to `http://web2.com`
Replace `your-server-ip` with the actual IP address or domain name of your Nginx server.
---
## Troubleshooting Common Issues
- **Error: 502 Bad Gateway**
- This error usually occurs if the backend server is down or unreachable. Verify that the backend server addresses (`http://web1.com`, `http://web2.com`) are correct and accessible.
- **Permission Denied for Log Files**
- Make sure the log file paths are writable by Nginx. Use `sudo chown www-data:www-data /var/log/nginx/reverse-proxy-access.log` if necessary.
- **Configuration Errors**
- Always test configuration changes using `sudo nginx -t` before reloading or restarting Nginx.
---

View File

@@ -0,0 +1,128 @@
# Setting Up Load Balancing with Nginx
Load balancing with Nginx helps distribute incoming traffic across multiple backend servers, improving the performance, reliability, and availability of your applications. This guide provides a step-by-step process to configure a basic round-robin load balancer using Nginx.
---
## Prerequisites
- **Nginx Installed**: Ensure Nginx is installed on your server.
- **Root or sudo privileges** to edit configuration files and restart Nginx.
- **Multiple Backend Servers**: Two or more backend servers with applications running. In this example, we use `10.10.10.1` and `10.10.10.2`.
---
## Step 1: Create the Load Balancer Configuration File
1. **Open a new configuration file** for the load balancer in Nginxs `sites-available` directory:
```bash
sudo vim /etc/nginx/sites-available/load_balancer.conf
```
2. **Define the Load Balancer Configuration**
Copy the following configuration into the file. Replace the IP addresses (`10.10.10.1` and `10.10.10.2`) with the actual IP addresses of your backend servers.
```nginx
# Define the upstream group of backend servers
upstream backend_servers {
server 10.10.10.1;
server 10.10.10.2;
}
server {
listen 80;
server_name _; # Accept any hostname or specify a domain name if needed
location / {
proxy_pass http://backend_servers; # Forward requests to the backend servers group
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Log files
access_log /var/log/nginx/load_balancer_access.log;
error_log /var/log/nginx/load_balancer_error.log;
}
```
### Explanation of Key Directives
- **upstream**: Defines a pool of backend servers to which Nginx will forward traffic. By default, Nginx uses a round-robin algorithm, sending requests to each server in turn.
- **server_name**: Accepts any hostname (`_`) or a specific domain name.
- **proxy_pass**: Specifies the backend server group defined by `upstream`.
- **proxy_set_header**: Passes client information such as the original IP and protocol to the backend servers.
- **access_log** and **error_log**: Directs logs to specified files for easier monitoring and troubleshooting.
---
## Step 2: Enable the Load Balancer Configuration
1. **Create a symbolic link** to `sites-enabled` to activate the load balancer configuration in Nginx:
```bash
sudo ln -s /etc/nginx/sites-available/load_balancer.conf /etc/nginx/sites-enabled/load_balancer.conf
```
2. **Verify Nginx Configuration**
Test the Nginx configuration for syntax errors:
```bash
sudo nginx -t
```
3. **Reload Nginx** to apply the new configuration:
```bash
sudo nginx -s reload
```
---
## Step 3: Test the Load Balancer
To ensure the load balancer is distributing traffic correctly, you can access the Nginx servers IP address or domain name in your web browser:
```
http://your-server-ip/
```
You should see responses from the backend servers. Testing multiple times should show responses alternating between `10.10.10.1` and `10.10.10.2`, as Nginx forwards requests in a round-robin fashion.
---
## Optional: Configure Additional Load Balancing Methods
Nginx supports multiple load balancing algorithms, which you can specify within the `upstream` block:
- **Round Robin (default)**: Distributes requests evenly across all servers.
- **Least Connections**: Directs traffic to the server with the fewest active connections.
```nginx
upstream backend_servers {
least_conn;
server 10.10.10.1;
server 10.10.10.2;
}
```
- **IP Hash**: Directs requests from the same client IP to the same backend server, which can help with session persistence.
```nginx
upstream backend_servers {
ip_hash;
server 10.10.10.1;
server 10.10.10.2;
}
```
---
## Troubleshooting Common Issues
- **Error: 502 Bad Gateway**
- This error often means that the backend server is unreachable or down. Verify the IP addresses and ensure each backend server is running and accessible.
- **Permission Denied for Log Files**
- Ensure the log file paths are writable by Nginx. Adjust permissions as needed:
```bash
sudo chown www-data:www-data /var/log/nginx/load_balancer_access.log
```
- **Configuration Errors**
- Always test configuration changes with `sudo nginx -t` before reloading or restarting Nginx.

View File

@@ -1,206 +0,0 @@
### Installing Packages from Ubuntu Repositories
1. Update your Ubuntu system:
```bash
sudo apt update
```
2. Install necessary packages:
```bash
sudo apt install python3-venv python3-dev libpq-dev postgresql postgresql-contrib nginx curl
```
### Creating the PostgreSQL Database and User
3. Log into an interactive Postgres session:
```bash
sudo -u postgres psql
```
4. Inside the PostgreSQL prompt, create a database for your project:
```sql
CREATE DATABASE myproject;
```
5. Create a database user for your project with a secure password:
```sql
CREATE USER myprojectuser WITH PASSWORD 'password';
```
6. Modify connection parameters for the user:
```sql
ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE myprojectuser SET timezone TO 'UTC';
```
7. Grant the new user access to administer the new database:
```sql
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
```
8. Exit the PostgreSQL prompt:
```sql
\q
```
### Creating a Python Virtual Environment for Your Project
9. Create a directory for your project files:
```bash
mkdir ~/myprojectdir
cd ~/myprojectdir
```
10. Create a Python virtual environment:
```bash
python3 -m venv myprojectenv
```
11. Activate the virtual environment:
```bash
source myprojectenv/bin/activate
```
12. Install Django, Gunicorn, and psycopg2:
```bash
pip install django gunicorn psycopg2-binary
```
### Creating and Configuring a New Django Project
13. Create a new Django project with a defined directory:
```bash
django-admin startproject myproject ~/myprojectdir
```
14. Adjust settings in the `settings.py` file:
- Set `ALLOWED_HOSTS` to `['*']`
- Configure `DATABASES` with PostgreSQL details
15. Add static root configuration to `settings.py`:
```python
import os
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
```
16. Migrate initial database schema:
```bash
~/myprojectdir/manage.py makemigrations
~/myprojectdir/manage.py migrate
```
17. Create an administrative user:
```bash
~/myprojectdir/manage.py createsuperuser
```
18. Collect static content:
```bash
~/myprojectdir/manage.py collectstatic
```
19. Allow port 8000:
```bash
sudo ufw allow 8000
```
20. Start Django development server:
```bash
~/myprojectdir/manage.py runserver 0.0.0.0:8000
```
21. Access your application in a web browser.
22. Stop Apache2 service:
```bash
sudo /etc/init.d/apache2 restart
```
### Testing Gunicorn
23. Test Gunicorn to ensure it can serve the application:
```bash
cd ~/myprojectdir
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
```
24. Stop Gunicorn:
- Press `CTRL-C`
### Creating systemd Socket and Service Files for Gunicorn
25. Create a systemd socket file for Gunicorn:
```bash
sudo nano /etc/systemd/system/gunicorn.socket
```
26. Create and open a systemd service file for Gunicorn:
```bash
sudo nano /etc/systemd/system/gunicorn.service
```
27. Configure the service file with appropriate details.
### Checking for the Gunicorn Socket File
28. Check the status of the Gunicorn socket:
```bash
sudo systemctl status gunicorn.socket
```
29. Check for the existence of the Gunicorn socket file:
```bash
file /run/gunicorn.sock
```
30. Check Gunicorn socket logs:
```bash
sudo journalctl -u gunicorn.socket
```
### Testing Socket Activation
31. Test the socket activation mechanism:
```bash
sudo systemctl status gunicorn
```
32. Send a connection to the socket through curl:
```bash
curl --unix-socket /run/gunicorn.sock localhost
```
### Configuring Nginx to Proxy Pass to Gunicorn
33. Create and open a new server block in Nginx's sites-available directory:
```bash
sudo nano /etc/nginx/sites-available/myproject
```
34. Configure the server block with appropriate settings.
35. Enable the server block:
```bash
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
```
36. Test Nginx configuration for syntax errors:
```bash
sudo nginx -t
```
37. Restart Nginx:
```bash
sudo systemctl restart nginx
```
38. Open firewall to normal traffic on port 80:
```bash
sudo ufw delete allow 8000
sudo ufw allow 'Nginx Full'
```
### Conclusion
You should now be able to access your Django application via your server's domain or IP address.

View File

@@ -1,113 +0,0 @@
# Deploying .NET on Linux
This tutorial has been tested only on .NET 7 and Ubuntu 22.04.
## Getting the Output
First, let's install .NET:
```bash
sudo apt install dotnet-sdk-7.0
```
*Note: You can create a .NET project using `dotnet new mvc` command.*
Then, we need to publish our project:
```bash
dotnet publish
```
The location of the output file will be displayed after the command finishes. Typically, the project output will be placed in:
**bin/Debug/net7.0/publish**
## Installing Nginx
**Nginx** is a high-performance web server with low resource usage, distributed under the terms of the BSD license. It runs on Unix-like operating systems and is widely used, currently powering 12.07% of the internet's domains.
To install **Nginx** via `apt`, use the following command:
```bash
sudo apt install nginx
```
Then, disable the firewall with:
```bash
sudo ufw disable
```
If you encounter an error with this command, it means you don't have a firewall. In that case, skip this part.
If the installation is successful, you should see "Welcome to Nginx" when typing `localhost` in your browser.
## Configuring Nginx
Create a directory for your site:
```bash
sudo mkdir /var/www/app1
```
Copy the contents of the `publish` directory to the newly created directory:
```bash
sudo cp yourprojectFolder/bin/Debug/net7.0/publish /var/www/app1
```
Then, navigate to the Nginx configuration:
```bash
sudo vim /etc/nginx/sites-available/default
```
Replace the contents of the file with the following:
```nginx
server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
*Note: Replace `example.com` with your site address.*
Check the configuration file syntax:
```bash
sudo nginx -t
```
If no errors are reported, reload Nginx to apply the changes:
```bash
sudo nginx -s reload
```
## Adding the Site as a Service
Create a service file for your site:
```bash
sudo vim /etc/systemd/system/app1.service
```
Copy the following code into the file:
```plaintext
[Unit]
Description=dotnet webapp
[Service]
WorkingDirectory=/var/www/app1
ExecStart=/usr/bin/dotnet /var/www/app/projectname.dll
Restart=always
RestartSec=10
SyslogIdentifier=projectname
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
```
*Note: Replace `projectname` with your project's name.*
Enable and start the site, and check its status:
```bash
sudo systemctl enable app1.service
sudo systemctl start app1.service
sudo systemctl status app1.service
```