Objective: By the end of this lesson, you will learn how to configure Nginx to listen on a new HTTPS port (7199) and forward all traffic to an HTTP service running on port 5199.
Prerequisites:
- Basic understanding of Nginx configuration.
- Access to Nginx configuration files.
- An active HTTP service running on port 5199.
Lesson Content:
- Introduction to Port Forwarding and Nginx Configuration:
- Understanding the concept of port forwarding and its applications.
- Brief overview of Nginx as a web server and a reverse proxy.
- Step 1: Configure Nginx to Listen on a New Port (7199):
- Edit the Nginx configuration file (
nginx.conf), usually found in/etc/nginx/or a similar directory. - In the
httpblock, add a newserverblock for port 7199:ssl_certificate /path/to/your/certificate.crt;server {
listen 7199 ssl;
server_name www.yourdomain.com;
ssl_certificate_key /path/to/your/private.key;location / {
proxy_pass http://localhost:5199;
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-Proto $scheme;
}
} - Replace
/path/to/your/certificate.crtand/path/to/your/private.keywith the paths to your SSL certificate and private key.
- Edit the Nginx configuration file (
- Step 2: Restart Nginx to Apply Changes:
- Run the following command to restart Nginx and apply your new configuration:
sudo systemctl restart nginx
- Nginx will now listen on port 7199 and forward requests to port 5199.
- Run the following command to restart Nginx and apply your new configuration:
- Step 3: Testing the Configuration:
- Open a web browser and go to
https://www.yourdomain.com:7199. - Check that the content served is from the HTTP service on port 5199.
- Open a web browser and go to
- Step 4: Adjust Firewall Settings (If Necessary):
- Ensure that the server’s firewall is configured to allow traffic on port 7199.
- Conclusion and Troubleshooting Tips:
- Summarize the key points of the lesson.
- Provide common troubleshooting tips for issues like Nginx not restarting, or the service not being accessible.
Assignment:
- Implement this port forwarding setup on your Nginx server.
- Test the setup by accessing
https://www.yourdomain.com:7199and ensure it proxies to the service on port 5199. - Document any challenges and solutions you encounter.
Additional Resources:
- Nginx Documentation on Reverse Proxy: Nginx Reverse Proxy
- Nginx Beginner’s Guide: Nginx Beginner’s Guide
Feedback and Support:
- For further queries or issues, consider consulting the Nginx community forums or seeking assistance from a network administrator.
