2

I am not getting any reply from ngix

nginx logs

2016/05/23 15:19:49 [error] 9019#0: *3 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.171.107.80, server: 54.169.34.178, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "54.169.34.178"

Previously I was only using uwsgi server, Now I want to add nginx at the front so that it can serve the static data and act as api-gateway.

I am trying to use this tutoriall. I was able to run the uwsgi server seperatly and when i combine it with nginx it's not working.

Can any one please help me on?

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

sites-enabled/*.conf

```

upstream testing {
server 127.0.0.1:8000;
}

server {
listen      80;

    server_name 54.169.34.178 
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste


    location / {
       uwsgi_pass testing;
        include     /home/ubuntu/testDjango/testWeb/uwsgi_params; 
    } 

}

```

zakir
  • 2,390
  • 2
  • 13
  • 16
  • you get this error while nginx is trying to serve static content or while it is proxying to your uwsgi server ? – avichalp May 23 '16 at 15:35
  • Currently I am not serving static content seperately. I am just trying to get the home page, which has all the necessery page in the single file – zakir May 23 '16 at 15:43
  • http://54.169.34.178:8000/ works fine for me on which I am running uwsgi. I am trying hit it by http://54.169.34.178/, But it doesn't work – zakir May 23 '16 at 15:43
  • can you please tell a bit about your uwsgi config like the host and port it binds to ? – avichalp May 23 '16 at 15:50
  • As of now, I am running like uwsgi --http :8000 --module testWeb.wsgi It works when you hit ipaddress:8000 – zakir May 23 '16 at 15:57
  • I think the answer might be here https://stackoverflow.com/a/27424043/671057 tldr: `uwsgi --socket :8002 --module wsgi.py` – gelbander Feb 02 '18 at 14:41

2 Answers2

0

As per the config and details you shared it seams like you are using uwsgi server which is bound to 0.0.0.0 (because you can access it here 54.169.34.178:8000) while in your nginx config you are setting upstream to 127.0.0.1. which is why nginx cannot reach your application.

I would suggest you to run your application at 127.0.0.1 by using the following command uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi

now try to access http://54.169.34.178/ from your browser.

avichalp
  • 1,100
  • 11
  • 11
  • I am getting the same error, Now I am unable to point the uwsgi even. When i tried Ipadderess:8000/- It doesn't work. And Nginx throwing the same error. – zakir May 23 '16 at 16:28
  • did you try `uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi`. here ipaddress is not any ipaddress but you localhost i.e. 127.0.0.1 ? – avichalp May 23 '16 at 16:31
  • Yes I did that(uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi). I am running in ec2 so just trying to hit http://54.169.34.178:8000/-, An I doing anything wrong here? – zakir May 23 '16 at 16:35
  • you should try `54.169.34.178:80` or just `54.169.34.178` because your nginx is listening on port 80. Now when nginx will receive a http request it will forward it to the upstream which in your case in `127.0.0.1:8000`. – avichalp May 23 '16 at 16:41
  • I understand that nginx is listening on port 80, I just want to check whether my backend application is working or not. when I hit the nginx now, I am getting the follwing error 2016/05/23 16:47:59 [error] 12078#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.171.107.80, server: 54.169.34.178, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "54.169.34.178" ~ – zakir May 23 '16 at 16:49
  • 1
    for further debugging I would suggest you to ssh into your ec-instance and test using curl. `curl http://127.0.0.1:8000` If curl works that means your service is running properly. Now go ahead and use above nginx config to make your service accessible from outside network. If curl doesn't work that means there is an issue with your backend service and you should debug that first. – avichalp May 23 '16 at 17:13
0

uwsgi_pass is not http protocol but uwsgi protocol which accept socket not http

when you do uwsgi_pass testing it expects socket so you need to run your uwsgi in socket mode and verify permissions on it (nginx should be able to read write to that file)

if you want to keep it at port and http you will have to change the uwsgi_pass into proxy_pass

Ami Mahloof
  • 472
  • 5
  • 10