Project: Share

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:

  1. 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.
  2. 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 http block, add a new server block for port 7199:
      server {
      listen 7199 ssl;
      server_name www.yourdomain.com;
      ssl_certificate /path/to/your/certificate.crt;
      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.crt and /path/to/your/private.key with the paths to your SSL certificate and private key.
  3. 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.
  4. 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.
  5. Step 4: Adjust Firewall Settings (If Necessary):
    • Ensure that the server’s firewall is configured to allow traffic on port 7199.
  6. 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:7199 and ensure it proxies to the service on port 5199.
  • Document any challenges and solutions you encounter.

Additional Resources:

Feedback and Support:

  • For further queries or issues, consider consulting the Nginx community forums or seeking assistance from a network administrator.