I'm learning nginx and uwsgi to deploy my Django web app. While learning them, I got confused with "socket" and "http".
.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.
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
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's socket
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With