Introduction: Why Pakistani Businesses Need Reverse Proxies
Managing web applications and internal company systems often requires exposing backend services to users. However, pointing public domains directly to high-numbered ports such as :3000, :8080, or :5000 creates significant security risks and looks unprofessional. In Pakistan, local businesses and institutions running custom web portals, accounting systems, or management software frequently face performance bottlenecks and security vulnerabilities when servers are misconfigured.
An Nginx reverse proxy acts as an intermediary server that receives public internet traffic on standard web ports (80 for HTTP and 443 for HTTPS) and routes those requests to the correct internal server application. By placing Nginx in front of your applications, you mask backend IP addresses, simplify SSL certificate installation, enable caching, and control access centrally. This step-by-step tutorial guides IT administrators, students, and technology managers in Pakistan through setting up an Nginx reverse proxy on an Ubuntu server.
Prerequisites for this Tutorial
Before proceeding with the configuration steps, ensure you have the following requirements ready:
- Ubuntu Server Installed: A dedicated physical machine or virtual server running Ubuntu 20.04 LTS or 22.04 LTS.
- SUDO Privileges: Access to a user account with administrative (root or sudo) command rights.
- Running Backend Application: A web service running on your server on an internal port (for example, a Node.js, Python, or PHP app listening on port
3000). - Registered Domain Name: A domain or subdomain (e.g.,
portal.yourcompany.pk) pointing to your server's public IP address via an A Record.
Step 1: Installing Nginx on Ubuntu Server
First, log into your server terminal via SSH and update the system's package index to ensure you install the latest stable version of Nginx.
Run the following system update commands in your terminal:
sudo apt updatesudo apt install nginx -y
Once the installation finishes, start the Nginx service and enable it to launch automatically whenever your server reboots:
sudo systemctl start nginxsudo systemctl enable nginx
You can verify that Nginx is active by checking its status using sudo systemctl status nginx. If active, you will see a green status indicating that the web server is running.
Step 2: Configuring Your First Nginx Server Block
Nginx manages individual site directives through text files called server blocks located in the /etc/nginx/sites-available/ directory. Rather than modifying the default system configuration, it is best practice to build a isolated configuration file for each application.
Create a new configuration file for your application using a text editor like Nano:
sudo nano /etc/nginx/sites-available/app.conf
Paste the following standard reverse proxy directive into the file. Replace portal.yourcompany.pk with your real domain name and 127.0.0.1:3000 with your backend application's IP address and port:
server {
listen 80;
server_name portal.yourcompany.pk;
location / {
proxy_pass http://127.0.0.1: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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Save the changes by pressing Ctrl + O, then Enter, and exit Nano by pressing Ctrl + X.
Step 3: Enabling and Testing the Nginx Configuration
Now that the server block file is written, you must enable it by creating a symbolic link from sites-available to the sites-enabled directory.
Execute the following symlink command:
sudo ln -s /etc/nginx/sites-available/app.conf /etc/nginx/sites-enabled/
Before restarting Nginx, always test the configuration files for syntax errors to avoid unexpected server downtime:
sudo nginx -t
If the terminal returns a success message stating that the syntax is OK, reload Nginx to apply your changes:
sudo systemctl reload nginx
At this point, any request sent to http://portal.yourcompany.pk will automatically be forwarded to your application running locally on port 3000.
Step 4: Securing the Proxy with Free SSL Encryption
Running web applications over unencrypted HTTP exposes sensitive company data to network interception. You can secure your Nginx reverse proxy using Let's Encrypt SSL certificates completely free of cost using Certbot.
Install Certbot and its dedicated Nginx integration plugin with this command:
sudo apt install certbot python3-certbot-nginx -y
Once installed, run Certbot to request and install an SSL certificate automatically:
sudo certbot --nginx -d portal.yourcompany.pk
Certbot will prompt you to enter an email address for renewal alerts and ask whether to redirect all HTTP traffic to HTTPS. Select the redirect option. Certbot will automatically edit your Nginx configuration file, apply SSL certificates, and set up an automatic renewal service.
Troubleshooting Common Nginx Proxy Issues in Pakistan
Even with proper configuration, local server environments can experience occasional errors. Here are practical fixes for common setup challenges:
- 502 Bad Gateway Error: This error occurs when Nginx cannot reach the backend server. Verify that your actual application service is running and listening on the designated port (e.g., test with
curl http://127.0.0.1:3000). - Unreachable Domain: Ensure your local firewall (UFW) permits web traffic. Run
sudo ufw allow 'Nginx Full'to unblock HTTP and HTTPS ports. - File Upload Limit Exceeded: Nginx defaults to a maximum upload size of 1MB. If your application handles larger files, add
client_max_body_size 50M;inside your Nginx server block.
Frequently Asked Questions (FAQs)
Can I host multiple applications behind a single Nginx reverse proxy?
Yes. You can create multiple server configuration files in /etc/nginx/sites-available/ for different domains or subdomains, routing each one to a separate internal port or IP address.
Does an Nginx reverse proxy work with local IP addresses without a public domain?
Yes. You can set the server_name to your local network server IP address (e.g., 192.168.10.50) to manage internal office applications locally without internet exposure.
How often do Let's Encrypt SSL certificates renew?
Let's Encrypt certificates are valid for 90 days. Certbot automatically schedules background daily checks to renew certificates within 30 days of expiration.
Streamline Your Server Infrastructure with NetBit Software House
Maintaining stable, secure, and fast server infrastructure is critical for business operations across Pakistan. Managing web servers, network routing, and software deployments demands technical precision and continuous oversight.
NetBit Tech provides end-to-end IT maintenance, server configuration, custom web development, and secure network infrastructure packages tailored for modern enterprises. Based in Khuzdar, NetBit Software House helps local businesses, educational institutes, and offices establish robust digital infrastructure with zero hassle.
Whether you need custom web software development, server deployment, network cabling, or full IT operational support, partner with the experts at NetBit Khuzdar. Contact NetBit Tech today to discuss your project requirements and receive a customized technical proposal for your business infrastructure.
Reader comments.
Share your question, suggestion or experience related to this article.
No comments yet
There are no approved comments on this article yet. You can be the first person to leave one.