Score:0

Nginx Forward All Traffic on All Ports Except Port 80

ru flag

I have a domain name, let's say example.com registered in Dynadot. I'm having it, along with subdomains www.example.com and cloud.example.com point to my IP address via A records. I have set up some servers that are accessible using this domain name. For example, my FTP server can be accessed using example.com:21. I have a Node.js server running on port 80, and a Nextcloud server running on port 85. The last thing I have set up is an Nginx server, which listens on port 80. Here is my Nginx configuration:

server {
    listen 80;
    server_name cloud.example.com;

    location / {
        proxy_pass http://example.com:85;
    }
}

server {
    listen 80;
    server_name www.example.com;

    location / {
        proxy_pass http://192.168.1.31;
    }
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://192.168.1.31;
    }
}

What this configuration does is:

  • If a user goes to example.com or www.example.com, it redirects them to my Node.js server.

  • If a user goes to cloud.example.com, it redirects them to my Nextcloud server, which is also accessible from example.com:85.

  • If a user wants to connect to another server running on a different port, they can use example.com:<port>

This works great, but my only problem is that my ISP blocks inbound traffic for port 80!

I tried to find a workaround for hours, and my only option is to use GoDaddy. I can host my Nginx server on GoDaddy, which points example.com and www.example.com to my Node.js server and points cloud.example.com to my Nextcloud server. This would work, but it means that example.com's DNS settings would need to be changed to an A record pointing to the GoDaddy servers. This would all work fine, but it means that I can no longer access any of my other servers, such as my FTP server because exmaple.com:21 would no longer point to <my IP>:21, but <GoDaddy Server IP>:21.

I was thinking, to solve this issue, I could configure my Nginx server so that it does what it did before, but if a user goes to example.com with ANY port other than port 80, it will forward the connection to <my IP>:<port>. That way, all my other servers, such as my FTP server will still be accessible through exmaple.com:21, but port 80 will not be blocked because the Nginx server which uses port 80 is being hosted on GoDaddy.

I don't know if this is possible with Nginx, though. If it is, what would the configuration look like? If it isn't, what other options do I have? (Other than buying my ISP's business plan to unblock port 80)

djdomi avatar
za flag
offtopic: Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User,
us flag
You should not use FTP, it is a security risk.
Denes Garda avatar
ru flag
@TeroKilkanen Why even mention that? In my question, an FTP server was just an example. Off-topic comment.
us flag
Providing solid security advice is always on-topic.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.