2017-03-23 8 views
0

Ich habe bereits 2 Server auf Digital Ocean ausgeführt und ich habe Nginx für Webserver und Nodejs für App-Server installiert.Nodejs Reverse-Proxy-Server (Nginx)

Für App-Server: Nodeapp Verzeichnis:/var/AppData/myapp/ NodeJS App auf 4680 Hafen läuft; jedoch in der App-Server Ich habe paar iptables-Optionen (Firewall)

IPTABLES Optionen I für appserver tat:

*filter 

# Default policy is to drop all traffic 
-P INPUT DROP 
-P FORWARD DROP 
-P OUTPUT DROP 

# Allow all loopback traffic 
-A INPUT -i lo -j ACCEPT 
-A OUTPUT -o lo -j ACCEPT 

# Allow ping. 
-A INPUT -p icmp -m state --state NEW --icmp-type 8 -j ACCEPT 

# Allow incoming SSH, HTTP and HTTPS traffic 
-A INPUT -i eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A OUTPUT -o eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT 

# Allow inbound traffic from established connections. 
# This includes ICMP error returns. 
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 

# Log what was incoming but denied (optional but useful). 
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 7 

# Allow outgoing SSH, HTTP and HTTPS traffic 
# This is useful because we won't be able to download and install 
# NPM packages otherwise and use git over SSH 
-A OUTPUT -o eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A INPUT -i eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT 

# Allow dns lookup 
-A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT 
-A INPUT -p udp -i eth0 --sport 53 -j ACCEPT 

# Set rate limits for DOS attack prevention (optional) 
# The rates here greatly depend on your application 
-A INPUT -p tcp -m multiport --dports 80,443 -m limit --limit 250/minute --limit-burst 1000 -j ACCEPT 

# Log any traffic which was sent to you 
# for forwarding (optional but useful). 
-A FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 7 

COMMIT 

Für Webserver Standardkonfiguration ist wie this-

listen 80 default_server; 
    listen [::]:80 default_server; 

    # SSL configuration 
    # 
    # listen 443 ssl default_server; 
    # listen [::]:443 ssl default_server; 
    # 
    # Note: You should disable gzip for SSL traffic. 
    # See: https://bugs.debian.org/773332 
    # 
    # Read up on ssl_ciphers to ensure a secure configuration. 
    # See: https://bugs.debian.org/765782 
    # 
    # Self signed certs generated by the ssl-cert package 
    # Don't use them in a production server! 
    # 
    # include snippets/snakeoil.conf; 

    root /var/www/html; 

    # Add index.php to the list if you are using PHP 
    index index.html index.htm index.nginx-debian.html; 

    server_name _; 

    location/{ 
      proxy_pass http://10.135.9.223:4680 ; 
      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; 
    } 

Mit diesen All Option Ich schreibe fast alles auf, was ich denke, aber wenn etwas verpasst bitte lass es mich erzählen. So ist das Hauptproblem hier ist wenn ich URL eingeben, für http://web-server-ip-address es 504 Gateway

EDIT abgelaufen antwortet: Wenn ich die Firewall deaktivieren, gibt es kein Problem.

+0

Firewall sagt '10.135.47.36', sagt nginx Config' 10.135.9.223'? Wenn der Node.js-Server lokal ausgeführt wird (zu nginx), verwenden Sie einfach "127.0.0.1". – robertklep

+0

das ist, weil ich nur dort 1223 port für webservers local-ip erlaubt –

+0

Ohh ich sehe, sie laufen auf zwei separaten (virtuellen) Servern. Sind Sie sicher, dass Sie 10.135.9.223:4680 vom Webserver erreichen können? Woher kommt Port 1223? Was hört darauf? – robertklep

Antwort

0

Disabled die Firewall und nehmen einen Vorteil auf cloudflare, wenn Sie mit diesen Arten von Fehlern nicht vertraut sind