<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://serverrental.store/index.php?action=history&amp;feed=atom&amp;title=Installing_and_Configuring_Nginx</id>
	<title>Installing and Configuring Nginx - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://serverrental.store/index.php?action=history&amp;feed=atom&amp;title=Installing_and_Configuring_Nginx"/>
	<link rel="alternate" type="text/html" href="https://serverrental.store/index.php?title=Installing_and_Configuring_Nginx&amp;action=history"/>
	<updated>2026-04-14T21:20:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://serverrental.store/index.php?title=Installing_and_Configuring_Nginx&amp;diff=5841&amp;oldid=prev</id>
		<title>Admin: New server guide</title>
		<link rel="alternate" type="text/html" href="https://serverrental.store/index.php?title=Installing_and_Configuring_Nginx&amp;diff=5841&amp;oldid=prev"/>
		<updated>2026-04-14T10:02:02Z</updated>

		<summary type="html">&lt;p&gt;New server guide&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This article provides a comprehensive guide to installing and configuring Nginx, a powerful and high-performance web server, on a Linux system. We'll cover everything from initial installation to advanced topics like virtual hosts, SSL certificates, reverse proxy setups, and performance tuning. This guide is suitable for beginners to intermediate system administrators looking to leverage Nginx for their web hosting needs.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
Before you begin, ensure you have the following:&lt;br /&gt;
&lt;br /&gt;
*   A server running a modern Linux distribution (e.g., Ubuntu 20.04 LTS, Debian 10, CentOS 8). For reliable performance, consider dedicated servers available at [https://powervps.net/?from=32 PowerVPS] with full root access.&lt;br /&gt;
*   Root or sudo privileges on your server.&lt;br /&gt;
*   Basic familiarity with the Linux command line.&lt;br /&gt;
*   A domain name (e.g., `example.com`) pointing to your server's public IP address.&lt;br /&gt;
&lt;br /&gt;
== Installing Nginx ==&lt;br /&gt;
&lt;br /&gt;
Nginx is available in the default repositories of most Linux distributions, making installation straightforward.&lt;br /&gt;
&lt;br /&gt;
=== On Debian/Ubuntu ===&lt;br /&gt;
&lt;br /&gt;
1.  **Update package lists:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo apt update&lt;br /&gt;
    ```&lt;br /&gt;
    This command synchronizes your local package index with the remote repositories, ensuring you install the latest available version.&lt;br /&gt;
&lt;br /&gt;
2.  **Install Nginx:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo apt install nginx&lt;br /&gt;
    ```&lt;br /&gt;
    This installs the Nginx web server and its dependencies.&lt;br /&gt;
&lt;br /&gt;
3.  **Verify installation and status:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl status nginx&lt;br /&gt;
    ```&lt;br /&gt;
    You should see output indicating that Nginx is `active (running)`. Press `q` to exit the status view.&lt;br /&gt;
&lt;br /&gt;
    ''Expected Output Snippet:''&lt;br /&gt;
    &amp;lt;pre&amp;gt;&lt;br /&gt;
    ● nginx.service - A high performance web server and a reverse proxy server&lt;br /&gt;
         Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)&lt;br /&gt;
         Active: active (running) since Mon 2023-10-27 10:00:00 UTC; 1min 30s ago&lt;br /&gt;
           Docs: man:nginx(8)&lt;br /&gt;
       Main PID: 12345 (nginx)&lt;br /&gt;
          Tasks: 2 (limit: 1153)&lt;br /&gt;
         Memory: 3.5M&lt;br /&gt;
            CPU: 50ms&lt;br /&gt;
         CGroup: /system.slice/nginx.service&lt;br /&gt;
                 ├─12345 /usr/sbin/nginx -g daemon on; master_process=on;&lt;br /&gt;
                 └─12346 nginx: worker process&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4.  **Configure firewall (if using UFW):**&lt;br /&gt;
    If you are using the Uncomplicated Firewall (UFW), you need to allow Nginx traffic.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo ufw allow 'Nginx Full'&lt;br /&gt;
    sudo ufw enable&lt;br /&gt;
    ```&lt;br /&gt;
    The 'Nginx Full' profile allows both HTTP (port 80) and HTTPS (port 443) traffic.&lt;br /&gt;
&lt;br /&gt;
=== On CentOS/RHEL ===&lt;br /&gt;
&lt;br /&gt;
1.  **Install EPEL repository (if not already present):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo dnf install epel-release -y&lt;br /&gt;
    ```&lt;br /&gt;
    The Extra Packages for Enterprise Linux (EPEL) repository provides additional packages, including newer versions of Nginx.&lt;br /&gt;
&lt;br /&gt;
2.  **Install Nginx:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo dnf install nginx -y&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
3.  **Start and enable Nginx:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl start nginx&lt;br /&gt;
    sudo systemctl enable nginx&lt;br /&gt;
    ```&lt;br /&gt;
    `start` begins the Nginx service immediately, while `enable` ensures it starts automatically on boot.&lt;br /&gt;
&lt;br /&gt;
4.  **Configure firewall (if using firewalld):**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo firewall-cmd --permanent --add-service=http&lt;br /&gt;
    sudo firewall-cmd --permanent --add-service=https&lt;br /&gt;
    sudo firewall-cmd --reload&lt;br /&gt;
    ```&lt;br /&gt;
    This opens ports 80 and 443 for web traffic.&lt;br /&gt;
&lt;br /&gt;
=== Testing the Installation ===&lt;br /&gt;
&lt;br /&gt;
Open your web browser and navigate to your server's IP address (e.g., `http://your_server_ip`). You should see the default Nginx welcome page. This confirms Nginx is installed and running correctly.&lt;br /&gt;
&lt;br /&gt;
== Configuring Virtual Hosts ==&lt;br /&gt;
&lt;br /&gt;
Virtual hosts (also known as server blocks in Nginx) allow you to host multiple websites on a single server. Each virtual host is configured in its own file.&lt;br /&gt;
&lt;br /&gt;
1.  **Create a directory for your website files:**&lt;br /&gt;
    Replace `example.com` with your domain name.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo mkdir -p /var/www/example.com/html&lt;br /&gt;
    ```&lt;br /&gt;
    The `-p` flag creates parent directories if they don't exist.&lt;br /&gt;
&lt;br /&gt;
2.  **Create a sample index file:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /var/www/example.com/html/index.html&lt;br /&gt;
    ```&lt;br /&gt;
    Add some basic HTML content:&lt;br /&gt;
    ```html&lt;br /&gt;
    &amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
    &amp;lt;html&amp;gt;&lt;br /&gt;
    &amp;lt;head&amp;gt;&lt;br /&gt;
        &amp;lt;title&amp;gt;Welcome to example.com!&amp;lt;/title&amp;gt;&lt;br /&gt;
    &amp;lt;/head&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
        &amp;lt;h1&amp;gt;Success! The example.com virtual host is working!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
    &amp;lt;/html&amp;gt;&lt;br /&gt;
    ```&lt;br /&gt;
    Save and exit (Ctrl+X, Y, Enter in nano).&lt;br /&gt;
&lt;br /&gt;
3.  **Set ownership and permissions:**&lt;br /&gt;
    Ensure Nginx can read your website files.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo chown -R $USER:$USER /var/www/example.com/html&lt;br /&gt;
    sudo chmod -R 755 /var/www/example.com/html&lt;br /&gt;
    ```&lt;br /&gt;
    This gives ownership to your current user for easy file management, and sets read/execute permissions for others.&lt;br /&gt;
&lt;br /&gt;
4.  **Create an Nginx server block configuration file:**&lt;br /&gt;
    Configuration files for Nginx virtual hosts are typically stored in `/etc/nginx/sites-available/` and then symlinked to `/etc/nginx/sites-enabled/`.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/nginx/sites-available/example.com&lt;br /&gt;
    ```&lt;br /&gt;
    Add the following configuration:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    server {&lt;br /&gt;
        listen 80;&lt;br /&gt;
        listen [::]:80;&lt;br /&gt;
&lt;br /&gt;
        root /var/www/example.com/html;&lt;br /&gt;
        index index.html index.htm index.nginx-debian.html;&lt;br /&gt;
&lt;br /&gt;
        server_name example.com www.example.com;&lt;br /&gt;
&lt;br /&gt;
        location / {&lt;br /&gt;
            try_files $uri $uri/ =404;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
    *   `listen 80;`: Tells Nginx to listen on port 80 for IPv4 connections.&lt;br /&gt;
    *   `listen [::]:80;`: Listens on port 80 for IPv6 connections.&lt;br /&gt;
    *   `root /var/www/example.com/html;`: Specifies the document root for this server block.&lt;br /&gt;
    *   `index index.html ...;`: Defines the order of files Nginx will look for when a directory is requested.&lt;br /&gt;
    *   `server_name example.com www.example.com;`: Matches requests for these domain names.&lt;br /&gt;
    *   `location / { ... }`: Handles requests for any URI. `try_files` attempts to serve the requested file, then a directory index, or returns a 404 error.&lt;br /&gt;
&lt;br /&gt;
5.  **Enable the server block:**&lt;br /&gt;
    Create a symbolic link from `sites-available` to `sites-enabled`.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
6.  **Remove the default configuration (optional but recommended):**&lt;br /&gt;
    To avoid conflicts, it's good practice to remove the default Nginx welcome page configuration.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo rm /etc/nginx/sites-enabled/default&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
7.  **Test Nginx configuration:**&lt;br /&gt;
    Always test your Nginx configuration before reloading the service.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nginx -t&lt;br /&gt;
    ```&lt;br /&gt;
    ''Expected Output:''&lt;br /&gt;
    &amp;lt;pre&amp;gt;&lt;br /&gt;
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok&lt;br /&gt;
    nginx: configuration file /etc/nginx/nginx.conf test is successful&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
8.  **Reload Nginx:**&lt;br /&gt;
    Apply the changes.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo systemctl reload nginx&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
Now, when you visit `http://example.com` in your browser, you should see the &amp;quot;Success!&amp;quot; message from your `index.html` file.&lt;br /&gt;
&lt;br /&gt;
== Securing with SSL/TLS (HTTPS) ==&lt;br /&gt;
&lt;br /&gt;
To secure your website and enable HTTPS, you'll need an SSL/TLS certificate. Let's Encrypt provides free certificates.&lt;br /&gt;
&lt;br /&gt;
=== Installing Certbot ===&lt;br /&gt;
&lt;br /&gt;
Certbot is a tool that automates the process of obtaining and renewing Let's Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
=== On Ubuntu/Debian ===&lt;br /&gt;
&lt;br /&gt;
1.  **Install Certbot and the Nginx plugin:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo apt install certbot python3-certbot-nginx -y&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
2.  **Obtain and install the certificate:**&lt;br /&gt;
    Replace `example.com` and `www.example.com` with your actual domain names.&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo certbot --nginx -d example.com -d www.example.com&lt;br /&gt;
    ```&lt;br /&gt;
    Certbot will guide you through the process, asking for your email address and agreeing to terms. It will then automatically modify your Nginx configuration to use the new certificate and set up automatic renewal.&lt;br /&gt;
&lt;br /&gt;
=== On CentOS/RHEL ===&lt;br /&gt;
&lt;br /&gt;
1.  **Install Certbot:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo dnf install certbot python3-certbot-nginx -y&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
2.  **Obtain and install the certificate:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo certbot --nginx -d example.com -d www.example.com&lt;br /&gt;
    ```&lt;br /&gt;
    Follow the prompts as described above.&lt;br /&gt;
&lt;br /&gt;
After running Certbot, it will typically ask if you want to redirect HTTP traffic to HTTPS. It's recommended to choose the redirect option for enhanced security.&lt;br /&gt;
&lt;br /&gt;
=== Testing SSL ===&lt;br /&gt;
&lt;br /&gt;
Visit your website using `https://example.com`. Your browser should show a padlock icon, indicating a secure connection. You can also use online SSL checker tools to verify your configuration.&lt;br /&gt;
&lt;br /&gt;
== Configuring Nginx as a Reverse Proxy ==&lt;br /&gt;
&lt;br /&gt;
A reverse proxy sits in front of one or more backend servers, forwarding client requests to them. This is useful for load balancing, security, and serving different applications from the same domain.&lt;br /&gt;
&lt;br /&gt;
Let's assume you have a backend application running on `http://localhost:3000`.&lt;br /&gt;
&lt;br /&gt;
1.  **Edit your Nginx server block configuration:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/nginx/sites-available/example.com&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
2.  **Modify the `location` block:**&lt;br /&gt;
    Replace the existing `location / { ... }` block with the following:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    location / {&lt;br /&gt;
        proxy_pass http://localhost:3000;&lt;br /&gt;
        proxy_set_header Host $host;&lt;br /&gt;
        proxy_set_header X-Real-IP $remote_addr;&lt;br /&gt;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;&lt;br /&gt;
        proxy_set_header X-Forwarded-Proto $scheme;&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
    *   `proxy_pass http://localhost:3000;`: Forwards requests to your backend application.&lt;br /&gt;
    *   `proxy_set_header ...`: These directives pass important information about the original client request to the backend application, which might otherwise only see the proxy's IP address.&lt;br /&gt;
&lt;br /&gt;
3.  **Test and reload Nginx:**&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nginx -t&lt;br /&gt;
    sudo systemctl reload nginx&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
Now, when you access `http://example.com` (or `https://example.com` if SSL is configured), Nginx will forward the request to your backend application.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
Nginx is known for its performance. Here are some common tuning parameters:&lt;br /&gt;
&lt;br /&gt;
1.  **Worker Processes:**&lt;br /&gt;
    Nginx can use multiple worker processes to handle requests concurrently. It's generally recommended to set this to the number of CPU cores your server has.&lt;br /&gt;
    Edit the main Nginx configuration file:&lt;br /&gt;
    ```bash&lt;br /&gt;
    sudo nano /etc/nginx/nginx.conf&lt;br /&gt;
    ```&lt;br /&gt;
    Find the `worker_processes` directive and set it:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    worker_processes auto; # Or set to the number of CPU cores&lt;br /&gt;
    ```&lt;br /&gt;
    `auto` is often sufficient, letting Nginx determine the optimal number.&lt;br /&gt;
&lt;br /&gt;
2.  **Worker Connections:**&lt;br /&gt;
    This directive specifies the maximum number of simultaneous connections that each worker process can handle.&lt;br /&gt;
    Inside the `events` block in `nginx.conf`:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    events {&lt;br /&gt;
        worker_connections 1024; # Adjust based on server resources and expected load&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
    A common starting point is 1024. For high-traffic sites, you might need to increase this and also adjust system limits (e.g., `/etc/security/limits.conf`).&lt;br /&gt;
&lt;br /&gt;
3.  **Keepalive Timeout:**&lt;br /&gt;
    Keeps a connection open for a specified time, reducing the overhead of establishing new connections.&lt;br /&gt;
    Inside the `http` block in `nginx.conf`:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    http {&lt;br /&gt;
        # ... other http settings&lt;br /&gt;
        keepalive_timeout 65;&lt;br /&gt;
        keepalive_requests 1000;&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
4.  **Gzip Compression:**&lt;br /&gt;
    Compresses responses before sending them to the client, reducing bandwidth usage and improving load times.&lt;br /&gt;
    Inside the `http` block in `nginx.conf`:&lt;br /&gt;
    ```nginx&lt;br /&gt;
    http {&lt;br /&gt;
        # ... other http settings&lt;br /&gt;
        gzip on;&lt;br /&gt;
        gzip_vary on;&lt;br /&gt;
        gzip_proxied any;&lt;br /&gt;
        gzip_comp_level 6;&lt;br /&gt;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
5.  **Browser Caching:**&lt;br /&gt;
    Instructs the browser to cache static assets, so they don't need to be re-downloaded on subsequent visits.&lt;br /&gt;
    Add this to your server block configuration (`/etc/nginx/sites-available/example.com`):&lt;br /&gt;
    ```nginx&lt;br /&gt;
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {&lt;br /&gt;
        expires 30d;&lt;br /&gt;
        add_header Cache-Control &amp;quot;public&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    ```&lt;br /&gt;
&lt;br /&gt;
After making any changes to `nginx.conf`, remember to test and reload Nginx:&lt;br /&gt;
```bash&lt;br /&gt;
sudo nginx -t&lt;br /&gt;
sudo systemctl reload nginx&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
*   **502 Bad Gateway:** Often indicates that Nginx cannot reach the backend application (e.g., a reverse proxy issue). Check if your backend application is running and accessible from Nginx. Verify `proxy_pass` directive and firewall rules.&lt;br /&gt;
*   **403 Forbidden:** Usually means Nginx doesn't have permission to read the requested file or directory. Check file permissions (`chmod`) and ownership (`chown`) for your web root.&lt;br /&gt;
*   **404 Not Found:** The requested file does not exist. Double-check the `root` directive in your server block and ensure the file path is correct. Also, verify `try_files` directive.&lt;br /&gt;
*   **Nginx Fails to Start/Reload:** Run `sudo nginx -t` to check for syntax errors in your configuration files. The output will point to the problematic line. Common issues include typos, missing semicolons, or incorrect directives.&lt;br /&gt;
*   **SSL Certificate Errors:** Ensure your domain name is correctly listed in the `server_name` directive and that Certbot successfully modified the configuration. Check the certificate expiration date.&lt;br /&gt;
&lt;br /&gt;
== Related Articles ==&lt;br /&gt;
&lt;br /&gt;
*   [[Firewall Configuration]]&lt;br /&gt;
*   [[Basic Linux Command Line]]&lt;br /&gt;
*   [[Securing your Server with SSH]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Web Server Setup]]&lt;br /&gt;
[[Category:Nginx]]&lt;br /&gt;
[[Category:Linux Administration]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>