Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a node.js process running at port 9500.

I'm using iptables to redirect 80 to 9500 so - iptables -t nat -L outputs:

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 9500

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

And iptables -L INPUT --line-numbers outputs:

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  anywhere             anywhere            
2    ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
3    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:18001
4    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
5    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:9500
6    DROP       all  --  anywhere             anywhere  

Everything is good except my node app is available at port 80 & 9500 - is there a way to have it only available at port 80? I've tried removing rule #5 but then I fail to get a connection.

share|improve this question
1  
what's the problem of having the service available also at port 9500? you could block with iptables access to port 9500 from the outside and allow from inside (for the redirect) if that bothers you (restrict rule 5). –  LinuxDevOps Apr 30 at 18:20
    
From an SEO perspective, it's never a good idea to have web page accessible from two URLs (ports count). BUT - how would you implement the inside/outside? It sounds promising. I'm barely functional when it comes to iptables config. –  stockholmux Apr 30 at 18:29
    
regarding SEO I'm not sure how google would learn about the non-standard web port or if it would treat it as different content but you could use the same tactics for de-duplication like one entry in the robots.txt file to disallow indexing of non-standard port, permanent redirects etc –  LinuxDevOps Apr 30 at 18:52
2  
@stockholmux Either set your node.js application to listen port 80 or make it listen port 9500 on the loopback interface (127.0.0.1). –  Spack Apr 30 at 19:05
    
Setting node.js to listen locally is cleaner, it won't expose port 9500 and you don't have to change any iptables rule: nodejs.org/api/net.html#net_socket_localaddress –  LinuxDevOps May 1 at 12:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.