A lightweight Bash script for generating Nginx reverse proxy configuration files without the overhead of full UI-based solutions.
This script was created to provide more direct control over Nginx reverse proxy configuration, especially for users who prefer or require CLI-driven workflows. While tools like Nginx Proxy Manager offer a great web interface, this script focuses on direct file manipulation and scripting flexibility. The long-term goal is to also offer a web interface that complements the CLI by writing and editing configuration files directly.
- Interactive menu-based or CLI usage
- Create or remove Nginx proxy site configurations
- Displays current Nginx version and directories
- Performs syntax validation on config before enabling
- Automatically restarts Nginx if changes are applied
- Works well for self-hosted apps behind firewalls, DMZs, or internal networks
These neccessary application can be installed by the script if not installed already
- Tested on Ubuntu 24.04 LTS, but compatible with other Debian-based systems.
- Nginx.
- CertBot
- Netcat
wget https://github.com/perezjnr/nginx-proxy-generator/releases/latest/download/nginx-proxy-generator.tar.gz
tar -xzf nginx-proxy-generator.tar.gz && cd nginx-proxy-generator
sudo chmod +x main.shTo install Nginx Manually(script can auto install):
sudo apt update
sudo apt install nginx- Checks if Nginx is installed.
- Confirms the existence of
/etc/nginx/sites-availableand/etc/nginx/sites-enabled. - Prompts the user for required values:
- Port to listen on
- Domain name
- Internal IP address of web app
- Creates a configuration file in
sites-available. - Validates configuration using
nginx -t. - Enables the site by linking it to
sites-enabled. - Restarts Nginx and confirms success.
Note: Existing files with the same name will be overwritten.
Run the script without arguments to access the interactive menu:
sudo ./main.sh| Option | Description |
|---|---|
| 1 | Add a new website configuration |
| 2 | Remove an existing website configuration |
| 3 | Display usage information |
| 4 | Display script information |
| 5 | Display current Nginx version |
| 6 | Show Nginx sites-available directory path |
| 7 | Show Nginx sites-enabled directory path |
| 8 | Request new SSL certificate |
| 9 | Exit |
You can run specific actions directly from the command line:
sudo ./main.sh [option]| Short Flag | Long Flag | Description |
|---|---|---|
-a |
--add |
Add a new website configuration |
-r |
--remove |
Remove an existing website configuration |
-h |
--help |
Display help/usage information |
-i |
--info |
Show detailed script information |
-v |
--version |
Display current installed Nginx version |
-s |
--sites-available |
Show sites-available directory path |
| '-c' | '--certbot' | Request new SSL certificate |
-e |
--sites-enabled |
Show sites-enabled directory path |
Example:
sudo ./main.sh --add
You're running a self-hosted app on 192.168.1.100:5000 and want to serve it externally at http://app.example.com.
- External visitors reach
app.example.com - Internally it goes to
192.168.1.100:5000 - Proxy should listen on default HTTP port (80)
sudo ./main.sh --addThen when prompted, enter:
- Listen Port:
80 - Domain Name:
app.example.com - Internal IP:
192.168.1.100 - Internal Port:
5000
This will:
- Generate a reverse proxy config
- Link it to
sites-enabled - Confirm if you want SSL cert and it will automatically request for Lets Encrypt certificate using certbot
- Reload Nginx
You're now live with a fully functional reverse proxy.
Features that may be added soon:
- Web interface (optional) to accompany CLI tool
- Improve SSL support for existing http sites
- Backup/restore of existing configurations
- Access logging, better validation and conflict checks
- Modular plugin-like add-ons (e.g., rate limiting, headers, etc.)Pull requests and suggestions are welcome! Feel free to fork this repo and propose new features or improvements.
MIT
Inspired by Nginx Proxy Manager and the need for low-footprint CLI-based tools in self-hosted environments.