Login

How to Set up Nginx as a Reverse Proxy in Plesk

Reverse Proxy in Plesk

In this tutorial, we will walk you through the process to set up Nginx as a reverse proxy in Plesk, a powerful configuration to enhance performance, improve security, and efficiently balance server loads. By using Nginx as a reverse proxy, you can ensure that client requests are routed to the appropriate backend servers, providing better control and monitoring over your web traffic.

What is a Reverse Proxy and How Does It Work?

A reverse proxy acts as an intermediary between the client and the server. While a standard proxy server forwards client requests to various servers on the internet, a reverse proxy works in the opposite direction. It receives requests from clients and forwards them to the backend server.

In a typical reverse proxy setup, the reverse proxy server (such as Nginx) handles the incoming requests, processes them, and forwards them to an appropriate backend server. The backend server then generates a response, which is sent back through the reverse proxy to the client. This setup can help with:

  • Load balancing: Distributing incoming requests across multiple servers to improve performance.
  • Security: Hiding the identity and internal structure of backend servers.
  • Caching: Serving static content to reduce the load on backend servers.
  • SSL termination: Handling secure HTTPS connections.

Why Use Nginx as a Reverse Proxy?

There are several reasons to consider using Nginx as a reverse proxy in Plesk:

  • Performance: Nginx can handle thousands of concurrent connections, making it ideal for high-traffic websites.
  • Security: Nginx can provide an additional layer of security by acting as a buffer between external clients and your backend servers.
  • Load Balancing: With Nginx, you can distribute client requests across multiple backend servers, improving the overall performance of your application.
  • TLS Encryption: Nginx can manage SSL/TLS encryption, ensuring secure communication between clients and the reverse proxy.

Steps to Set up Nginx as a Reverse Proxy in Plesk

Follow these steps to set up Nginx as a reverse proxy in Plesk:

  1. Log in to Plesk:
    Plesk login
    Log in to your Plesk account as the root user.
  2. Navigate to Tools & Settings:
    Once logged in, go to “Tools & Settings” in the left sidebar.
    Plesk Tools & Settings
  3. Access Restricted Mode Settings:
    In the “Plesk” section, click on “Restricted Mode Settings”.
    nginx configuration
  4. Modify the Nginx Configuration:
    • In the “Web Server” tab, scroll down to find the “Nginx configuration” section.
    • Uncheck “proxy mode” and add the following Nginx directives in the “Additional Nginx Directives” field:
      location / {
      
      proxy_pass http://server_IP:3000;
      
      proxy_redirect off;
      
      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-Host $server_name;
      
      }
    • Make sure to replace server_IP with your actual server IP address.
    • After making the changes, click on Apply.

Additional Nginx Directives for Plesk

Once the Nginx reverse proxy is set up, you may want to add additional directives for specific configurations. These include directives to handle caching, security, and load balancing more effectively.
Additional nginx directives

Caching Configuration:
You can use Nginx to cache static content, reducing the load on your backend server.

location / {
proxy_pass http://server_IP:3000;
proxy_cache my_cache;
proxy_cache_valid 200 1h;
}

Security Enhancements:
Configure headers to improve the security of your server and prevent certain types of attacks.

location / {
proxy_pass http://server_IP:3000;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
}

Load Balancing:
If you have multiple backend servers, you can configure Nginx to distribute traffic across them.

upstream backend {
server backend1_IP;
server backend2_IP;
}

location / {
proxy_pass http://backend;
}

Conclusion

By following the steps outlined above, you have successfully learned how to set up Nginx as a reverse proxy in Plesk. This setup enhances the security, performance, and scalability of your web applications. Whether you need to distribute traffic across multiple servers or secure your internal resources, Nginx is a powerful tool for improving the efficiency and security of your infrastructure.

If you encounter any difficulties during the setup process, feel free to reach out to your hosting provider or contact our support team for further assistance.

For web hosting deals visit: host.co.in

Sarang Khedkar

How to Set up Nginx as a Reverse Proxy in Plesk
Table of Contents
    ×