This tutorial will guide you through setting up a reverse proxy in Nginx when using HestiaCP. The instructions are based on a community discussion where users solved this configuration challenge.
Understanding the Problem
When trying to set up a reverse proxy in HestiaCP, users often encounter issues because:
- HestiaCP automatically generates and manages Nginx configurations
- Directly editing Nginx config files may lead to changes being overwritten
- The standard location for custom configurations isn’t immediately obvious
Solution: Using Custom Templates
HestiaCP provides a way to customize server configurations without modifying the auto-generated files. Here’s how to properly add a reverse proxy:
Step 1: Locate or Create the Custom Template Directory
- Connect to your server via SSH
- Navigate to the HestiaCP template directory:
cd /usr/local/hestia/data/templates/web/nginx/
Step 2: Create a Custom Template
- Copy the default PHP-FPM template to use as a base:
cp -r php-fpm/ php-fpm-proxy
- Edit the new template’s files. The main file you need to modify is:
nano php-fpm-proxy/template.tpl
Step 3: Add Reverse Proxy Configuration
In the template.tpl
file, add your reverse proxy configuration inside the server block. Here’s an example:
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Save the file after making your changes.
Step 4: Apply the New Template
- In HestiaCP’s web interface, go to the domain you want to configure
- Change the “Web Template” to your new “php-fpm-proxy” template
- Save the changes
Step 5: Restart Nginx
For the changes to take effect:
sudo systemctl restart nginx
Alternative Solution: Using a Custom Configuration File
If you prefer not to create a custom template, you can add your reverse proxy configuration to a custom include file:
- Create a new file in your domain’s
conf
directory:
nano /home/user/conf/web/domain.com/nginx.custom.conf
- Add your reverse proxy configuration there
- HestiaCP will automatically include this file in the main Nginx configuration
Important Notes
- Always back up your configuration files before making changes
- Test your Nginx configuration before restarting:
nginx -t
- If you encounter issues, check the Nginx error logs:
tail -f /var/log/nginx/error.log
Conclusion
By following either the custom template method or the custom configuration file approach, you can successfully add a reverse proxy to your Nginx setup in HestiaCP without having your changes overwritten by the control panel’s automatic configuration management.
reference: Nginx add reverse proxy – Community Support / Install & Set-Up – Hestia Control Panel – Discourse
No responses yet