Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: 400 bad request ('xxxxx') when using Uwsgi to connect Nginx and Djanog #24

Open
creamidea opened this issue Sep 16, 2016 · 3 comments

Comments

@creamidea
Copy link
Owner

This is a disgust problem!!!

One way of solving this problem is to watch the error.log

First, you should know which encode the system is using. You can use locale to look at.
Second, make sure your nginx is using the same code as the system. You can put this in nginx.conf

http {
    ...
    charset utf-8;
    large_client_header_buffers 4 16k; # maybe
    ...
}

At last, make sure your Django(Python) using the same code as the nginx. You can put this code in your /your/path/to/lib/python2.7/sitecustomize.py.

# encoding=utf8
import sys

reload(sys)
sys.setdefaultencoding("utf-8")

Good luck.

PS: uwsgi ini file format

[uwsgi]
# Django-related settings
# the virtualenv (full path)
# virtualenv    = /opt/weixnpy/
# the base directory (full path)
chdir = /home/www/xxxxx/wx/weixnpy
# Django's wsgi file
module          = weixnpy.wsgi
#module          = weixnpy.wsgi:application
env             = DJANGO_SETTINGS_MODULE = weixnpy.settings
home            = /opt/weixnpy/ # your virtual environment
# py-programname          = /usr/local/bin/python2.7
# pythonpath      = /home/www/icslg/wx/weixnpy/ 

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 4
# the socket (use the full path to be safe
# socket          = 127.0.0.1:8001
socket          = /tmp/xxxxxxx.sock
# socket          = /var/run/weixn.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
chown-socket = www:www
# clear environment on exit
vacuum          = true
logto           = /var/log/uwsgi.log
@creamidea
Copy link
Owner Author

BTW, here is the nginx proxy inverse

server
{
    listen 80;
    server_name xxx456.tk;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.10.40:80;
    }
    access_log logs/xxx456.tk_access.log;
}

@creamidea
Copy link
Owner Author

Nginx configure:

http {
  ...
  upstream django {
    # server 127.0.0.1:8001;
    server unix:///tmp/xxxxx.sock;
  }
  ...
  server {
    ...
    location /zdl {
      include     /home/wweixnpy/uwsgi_params;
      uwsgi_pass  django;
    }
    location /weixnpystatic {
      alias /home/weixnpy/static;
    }
  }
}

@creamidea
Copy link
Owner Author

Test that uwsgi process is still alive every minute. (maybe, it is fine for you to run the crontab using the same account as uwsgi.

$ crontab -e
* * * * * /bin/bash /home/wx/weixnpy/watch_dog.sh > /dev/null 2>&1

At last, make sure it is running.

$ crontab -l
$ sudo /etc/init.d/crond status # restart

XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant