Search

Install Nginx on CentOS 9 Stream with a Virtual Host

3 min read
7 views

If you're new to server administration or web hosting, setting up CentOS 9 Stream might seem like a daunting task. But fear not! With a step-by-step approach, you'll be able to install Nginx on CentOS 9 Stream in no time. Let's dive in and get started on this exciting journey.

Prompt
sudo dnf install nginx

Sit back and relax while the installation process takes care of everything for you. Once it's done, you'll have Nginx ready to go.

    Prompt
    server { listen 80; server_name yourdomain.com; root /var/www/mywebsite; index index.html; location / { try_files $uri $uri/ =404; } }

Replace yourdomain.com with your actual domain name and /var/www/mywebsite with the directory where your website files are located.

    Step 3: Test and Apply the Configuration

    Before we finalize the setup, let's test the configuration to ensure everything is in order. Run the following command:

    Prompt
    sudo nginx -t

    If there are no syntax errors, you should see a message saying "syntax is ok" and "configuration file /etc/nginx/nginx.conf test is successful." If you encounter any errors, double-check your configuration file for any typos or mistakes.

    Once the test is successful, apply the configuration changes by reloading Nginx:

    Prompt
    sudo systemctl reload nginx</code> <h3 class="wp-block-heading'>Step 4: Update DNS or Hosts File</h3> <p>To access your website using the domain name you specified, you need to update your DNS settings or add an entry in your local hosts file. If you're hosting the website locally for testing purposes, edit the hosts file with the following command:</p> <pre class="wp-block-code'><code>sudo nano /etc/hosts

    Add the following line at the end of the file:

    Prompt
    127.0.0.1 yourdomain.com

    Save the file and exit the editor.

Share this article

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!