简体   繁体   中英

What are the differences between http and socket inside of ini file in uWSGI?

I'm learning nginx and uwsgi to deploy my Django web app. While learning them, I got confused with "socket" and "http".

I think I should write .ini like the following.

when I use only uwsgi ... http=127.0.0.1:8001 ...

when I use uwsgi and nginx and I want to make clients connect to my server through nginx ... socket=127.0.0.1:8001 ...

When I only use uwsgi to run my server, I guess I should use "http" instead of "socket" in .ini file http=127.0.0.1:8001 because if i use "socket" it emits errors when clients connect to my server, like this. invalid request block size: 21573 (max 4096)...skip

However, when I use nginx with uwsgi, I should use socket instead of http . If I use http , I guess the server emitted timeout error.

My codes

this is my codes that works in /etc/nginx/sites-available/blog.conf

upstream blog{
    server 127.0.0.1:8001;
}

server {
    listen 80;
    server_name 127.0.0.1;
    charset     utf-8;

    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /django_static/djProject;
    }

    location / {
        include /etc/nginx/uwsgi_params;
        uwsgi_pass  blog;
    }
}

in project directory, app.ini

[uwsgi]
plugins=python3
chdir={myProject location}
module=djProject.wsgi:application
# Settings module, relative to the chdir path
env='DJANGO_SETTINGS_MODULE=djProject.settings'
# Python virtual env path
home=/home/su/uwsgi/uwsgi-tutorial
# File used for uwsgi to send signals and start/stop

socket=127.0.0.1:8001
#http=127.0.0.1:8001
master=True
processes=4
harakiri=20
max-requests=5
vacuum=True
enable-threads=true

static-map = /static=/django_static/djProject

In conclusion

How different are they to use http and socket in .ini file and when should I use them respectively?

expanding on what Ranjeet said, you need to make sure everything is communicating using compatible protocols. Nginx's uwsgi_pass option tells it to use a "special" uwsgi protocol. while uWSGI'ssocket option is documented as using its "default protocol" which seems to actually mean it uses the same "special" uwsgi protocol, but you could use the uwsgi-socket option to be more explicit.

looking through uwsgi's the code in uwsgi.c and socket.c it's pretty obvious that uwsgi-socket is just an alias for socket . it'd be nice if the docs also said that!

if you configure uWSGI with the http option you're telling it to use the http protocol, which won't do anything useful because NGINX is trying to talk to it using the above special uwsgi protocol. note that you could also configure NGINX to talk to uWSGI using HTTP, but this would lose information as you're basically then proxying and NGINX would have to rewrite headers to say it was proxying and would basically end up doing more work

see also https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html which has got lots of stuff about getting things taking to each other, you can just ignore the Django bits!

Don't confuse with these two different items (uwsgi and http).

As you already mentioned, you are deploying python application with uwsgi and nginx server.

Before go further, look on the client request to server (nginx)

Browser <-> nginx <-> socket <-> uwsgi <-> python application.

Nginx is responsible for to serve html, javascript and css files.

Nginx can't communicate with python application directly. Because python application standard way to publish applications via web server is WSGI. That's why we need a uwsgi server. That basically communicate with python application and handle request and response from/to web server nginx.

And Web server/ HTTP server communicate with uwsgi server via socket connection.

However, when I use nginx with uwsgi, I should use socket instead of http. If I use http, I guess the server emitted timeout error.

Yes your right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM