csdreamdong
V2EX  ›  问与答

求助一个 nginx+uwsgi+iptables 环境下遇到的问题。

  •  
  •   csdreamdong · Jul 4, 2016 · 2100 views
    This topic created in 3615 days ago, the information mentioned may be changed or developed.
    cat /etc/nginx/conf.d/default.conf
    
    server {
        listen       80;
        server_name  www.xxx.xxx;
        
        charset utf-8;
    
        location /test {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:3031;
        }
    }
    
    cat /etc/mblog/mblog.ini
    
    [uwsgi]
    socket = 127.0.0.1:3031
    pidfile = /run/mblog.pid
    wsgi-file = /usr/share/web_workspace/wsgi.py 
    logto = /var/log/mblog.log
    enable-threads = true
    callable = app
    processes = 2
    threads = 2
    
    iptables -nL
    
    Chain INPUT (policy DROP)
    target     prot opt source               destination         
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:10086
    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:53
    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination         
    
    

    主要的配置和环境就是以上的信息。现在遇到了这个问题: 访问 www.xxx.xxx 后,就一直在等待响应。。最终就是超时。 看了下 nginx 的日志,就是 uwsgi 的超时导致的。。 如果关掉 iptables 后,就可以正常访问了。。 所以是哪一步出问题了??

    nginx 的 errorlog

    2016/07/04 13:06:06 [error] 3689#3689: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: www.xxx.xxx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "www.xxx.xxx"
    
    4 replies    2016-07-04 14:39:59 +08:00
    sujin190
        1
    sujin190  
       Jul 4, 2016
    uwsgi 中又请求了其他网站的接口?或是访问了其他机器的数据库之类的
    csdreamdong
        2
    csdreamdong  
    OP
       Jul 4, 2016
    @sujin190 木有。 uwsgi 中,,就一个 hello , world 的输出。
    sujin190
        3
    sujin190  
       Jul 4, 2016
    @csdreamdong 你可以 telnet 连一下端口看看
    csdreamdong
        4
    csdreamdong  
    OP
       Jul 4, 2016
    @sujin190 我知道哪里错了

    iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
    本地地址的访问控制加一条。就可以了。- -
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   949 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:42 · PVG 05:42 · LAX 14:42 · JFK 17:42
    ♥ Do have faith in what you're doing.