[mezzanine-users] error happened when serving two mezzanine sites with nginx+uwsgi

2014-08-27 Thread Wesley

Hi guys,
   I hit a problem when using nginx+uwsgi to serve two mezzanine sites upon 
one VPS.
I use virtualenvwrapper to create a env with python2.7.6, note that 
system(centos6.5) has default python2.6.

Here is my uwsgi.xml:

  127.0.0.1:9000
  100
  true
  /usr/local/nginx/uwsgi.pid
  8
  /home/Portal
  /home
  wsgi
  true
  true
  true
  true
  6048
  /home/django.log


here is django uwsgi files included in nginx conf:
1. django_uwsgi.xml:
server {
listen  80;
server_name happydiaosi.com;
location / {
uwsgi_pass   127.0.0.1:9000;
include uwsgi_params;
uwsgi_param UWSGI_CHDIR /home/Portal;
uwsgi_param UWSGI_SCRIPT wsgi;
uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276;
#uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal;
#uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6;
   access_log  off;
}
location /static/ {
root/home/Portal/;
access_log  off;
log_not_found   off;
autoindex on;
}
 }

2. django_uwsgi2.xml 
# Django project
server {
listen  80;
server_name eason.happydiaosi.com;
location / {
uwsgi_pass   127.0.0.1:9000;
include uwsgi_params;
uwsgi_param UWSGI_CHDIR /home/EasonPortal;
uwsgi_param UWSGI_SCRIPT wsgi;
uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276;
#uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal;
#uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6;
   access_log  off;
}
location /static/ {
root/home/EasonPortal/;
access_log  off;
log_not_found   off;
}
 }

So, after I start uwsgi and nginx, when access from browser, it raises:
Traceback (most recent call last):
  File "/home/EasonPortal/wsgi.py", line 16, in 
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi

actually, within the py276, I can import .
So,here is sys.path of py276: 
(py276)[root@show python2.7]# python
Python 2.7.6 (default, Aug 27 2014, 02:35:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[31326 refs]
>>> sys.path
['', '/home/pyvirenvs/py276/lib/python27.zip', 
'/home/pyvirenvs/py276/lib/python2.7', 
'/home/pyvirenvs/py276/lib/python2.7/plat-linux2', 
'/home/pyvirenvs/py276/lib/python2.7/lib-tk', 
'/home/pyvirenvs/py276/lib/python2.7/lib-old', 
'/home/pyvirenvs/py276/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', 
'/usr/local/lib/python2.7/lib-tk', 
'/home/pyvirenvs/py276/lib/python2.7/site-packages']

And, here is output from wsgi.py(I add code to print sys.path in wsgi.py):

['/home/pyvirenvs/py276/lib/python2.6', '/home/EasonPortal', 
'/usr/lib64/python26.zip', '/usr/lib64/python2.6', 
'/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', 
'/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', 
u'/home']


So, why the path for wsgi looks like above? why everytime pointed to 
python26 which doesn't exist,say,/home/pyvirenvs/py276/lib/python2.6,
it should be python2.7 under /home/pyvirenvs/py276/lib, not python2.6...

What wrong here? Anything wrong with my uwsgi.xml or django_uwsgi.conf 
files?

Thanks.
Wesley

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] error happened when serving two mezzanine sites with nginx+uwsgi

2014-08-27 Thread Matt Gushee
Hi, Wesley--

I can't claim to be a uWSGI expert (can anyone? ;-) ), but I do have a
mezzanine site running with uWSGI & nginx. My setup is quite different
from yours (e.g. my OS is FreeBSD, and though I have only one
Django-based site, I'm also hosting a couple of other sites that are
not Python-based at all), so I don't know that my configuration will
help you.

But I do have a couple of questions for you.

1) Have you read this tutorial?
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

2) Where is your uWSGI installed? Is it installed in your virtualenv,
or in your system-wide python library, or is a standalone build? The
above tutorial recommends installing it in your virtualenv. I am using
a system-wide standalone version, and it works fine; the main reason I
do that is because of the non-python sites. It may also be relevant
that unlike most Linux distros, FreeBSD does not assume that you have
Python installed at all, let alone what version of Python you have or
where it is located. Anyway, I have a wild guess about this: if you
are using a system-wide version of uWSGI integrated into the Python
library, perhaps it thinks your Python executable is 2.6.

Beyond that ... I'm hesitant to say that your config looks wrong, but
I'm unfamiliar with your approach - especially running multiple apps
with one uWSGI config, using the Nginx config to distinguish between
them. Where did you learn to do that? I run uWSGI in emperor mode,
with a separate config file for each application.

It does appear to me that some of the variables being passed from
Nginx are redundant. Although none of them seem obviously relevant to
your issue, I think eliminating duplication would make it easier to
reason about the problem. E.g. define PYHOME once in the uWSGI config
instead of twice in the Nginx config. Also,  a minor point, but are
you sure there is a variable called UWSGI_SCRIPT? I can't find it
listed in the uWSGI documentation (which may or may not mean it isn't
there ;-) ).

Hope that helps a bit.

--
Matt Gushee

On Wed, Aug 27, 2014 at 5:11 AM, Wesley  wrote:
>
> Hi guys,
>I hit a problem when using nginx+uwsgi to serve two mezzanine sites upon
> one VPS.
> I use virtualenvwrapper to create a env with python2.7.6, note that
> system(centos6.5) has default python2.6.
>
> Here is my uwsgi.xml:
> 
>   127.0.0.1:9000
>   100
>   true
>   /usr/local/nginx/uwsgi.pid
>   8
>   /home/Portal
>   /home
>   wsgi
>   true
>   true
>   true
>   true
>   6048
>   /home/django.log
> 
>
> here is django uwsgi files included in nginx conf:
> 1. django_uwsgi.xml:
> server {
> listen  80;
> server_name happydiaosi.com;
> location / {
> uwsgi_pass   127.0.0.1:9000;
> include uwsgi_params;
> uwsgi_param UWSGI_CHDIR /home/Portal;
> uwsgi_param UWSGI_SCRIPT wsgi;
> uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276;
> #uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal;
> #uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6;
>access_log  off;
> }
> location /static/ {
> root/home/Portal/;
> access_log  off;
> log_not_found   off;
> autoindex on;
> }
>  }
>
> 2. django_uwsgi2.xml
> # Django project
> server {
> listen  80;
> server_name eason.happydiaosi.com;
> location / {
> uwsgi_pass   127.0.0.1:9000;
> include uwsgi_params;
> uwsgi_param UWSGI_CHDIR /home/EasonPortal;
> uwsgi_param UWSGI_SCRIPT wsgi;
> uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276;
> #uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal;
> #uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6;
>access_log  off;
> }
> location /static/ {
> root/home/EasonPortal/;
> access_log  off;
> log_not_found   off;
> }
>  }
>
> So, after I start uwsgi and nginx, when access from browser, it raises:
> Traceback (most recent call last):
>   File "/home/EasonPortal/wsgi.py", line 16, in 
> from django.core.wsgi import get_wsgi_application
> ImportError: No module named django.core.wsgi
>
> actually, within the py276, I can import .
> So,here is sys.path of py276:
> (py276)[root@show python2.7]# python
> Python 2.7.6 (default, Aug 27 2014, 02:35:36)
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import sys
> [31326 refs]
 sys.path
> ['', '/home/pyvirenvs/py276/lib/python27.zip',
> '/home/pyvirenvs/py276/lib/python2.7',
> '/home/pyvirenvs/py276/lib/python2.7/plat-linux2',
> '/home/pyvirenvs/py276/lib/python2.7/lib-tk',
> '/home/pyvirenvs/py276/lib/python2.7/lib-old',
> '/home/pyvirenvs/py276/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2',
> '/usr/local/lib/python2

Re: [mezzanine-users] error happened when serving two mezzanine sites with nginx+uwsgi

2014-08-27 Thread Wesley
Hi Matt,
   Thanks for your answer.
I solved the problem.

The reason is my uwsgi is installed upon system python2.6, I haven't 
installed for the virtual env python2.7.
So, to fix this:
1. activate the virtual env
2. pip install uwsgi
3. run uwsgi from the virtual env

Thanks.
Wesley

在 2014年8月28日星期四UTC+8上午1时31分57秒,Matt Gushee写道:
>
> Hi, Wesley-- 
>
> I can't claim to be a uWSGI expert (can anyone? ;-) ), but I do have a 
> mezzanine site running with uWSGI & nginx. My setup is quite different 
> from yours (e.g. my OS is FreeBSD, and though I have only one 
> Django-based site, I'm also hosting a couple of other sites that are 
> not Python-based at all), so I don't know that my configuration will 
> help you. 
>
> But I do have a couple of questions for you. 
>
> 1) Have you read this tutorial? 
> http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html 
>
> 2) Where is your uWSGI installed? Is it installed in your virtualenv, 
> or in your system-wide python library, or is a standalone build? The 
> above tutorial recommends installing it in your virtualenv. I am using 
> a system-wide standalone version, and it works fine; the main reason I 
> do that is because of the non-python sites. It may also be relevant 
> that unlike most Linux distros, FreeBSD does not assume that you have 
> Python installed at all, let alone what version of Python you have or 
> where it is located. Anyway, I have a wild guess about this: if you 
> are using a system-wide version of uWSGI integrated into the Python 
> library, perhaps it thinks your Python executable is 2.6. 
>
> Beyond that ... I'm hesitant to say that your config looks wrong, but 
> I'm unfamiliar with your approach - especially running multiple apps 
> with one uWSGI config, using the Nginx config to distinguish between 
> them. Where did you learn to do that? I run uWSGI in emperor mode, 
> with a separate config file for each application. 
>
> It does appear to me that some of the variables being passed from 
> Nginx are redundant. Although none of them seem obviously relevant to 
> your issue, I think eliminating duplication would make it easier to 
> reason about the problem. E.g. define PYHOME once in the uWSGI config 
> instead of twice in the Nginx config. Also,  a minor point, but are 
> you sure there is a variable called UWSGI_SCRIPT? I can't find it 
> listed in the uWSGI documentation (which may or may not mean it isn't 
> there ;-) ). 
>
> Hope that helps a bit. 
>
> -- 
> Matt Gushee 
>
> On Wed, Aug 27, 2014 at 5:11 AM, Wesley > 
> wrote: 
> > 
> > Hi guys, 
> >I hit a problem when using nginx+uwsgi to serve two mezzanine sites 
> upon 
> > one VPS. 
> > I use virtualenvwrapper to create a env with python2.7.6, note that 
> > system(centos6.5) has default python2.6. 
> > 
> > Here is my uwsgi.xml: 
> >  
> >   127.0.0.1:9000 
> >   100 
> >   true 
> >   /usr/local/nginx/uwsgi.pid 
> >   8 
> >   /home/Portal 
> >   /home 
> >   wsgi 
> >   true 
> >   true 
> >   true 
> >   true 
> >   6048 
> >   /home/django.log 
> >  
> > 
> > here is django uwsgi files included in nginx conf: 
> > 1. django_uwsgi.xml: 
> > server { 
> > listen  80; 
> > server_name happydiaosi.com; 
> > location / { 
> > uwsgi_pass   127.0.0.1:9000; 
> > include uwsgi_params; 
> > uwsgi_param UWSGI_CHDIR /home/Portal; 
> > uwsgi_param UWSGI_SCRIPT wsgi; 
> > uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276; 
> > #uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal; 
> > #uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6; 
> >access_log  off; 
> > } 
> > location /static/ { 
> > root/home/Portal/; 
> > access_log  off; 
> > log_not_found   off; 
> > autoindex on; 
> > } 
> >  } 
> > 
> > 2. django_uwsgi2.xml 
> > # Django project 
> > server { 
> > listen  80; 
> > server_name eason.happydiaosi.com; 
> > location / { 
> > uwsgi_pass   127.0.0.1:9000; 
> > include uwsgi_params; 
> > uwsgi_param UWSGI_CHDIR /home/EasonPortal; 
> > uwsgi_param UWSGI_SCRIPT wsgi; 
> > uwsgi_param UWSGI_PYHOME /home/pyvirenvs/py276; 
> > #uwsgi_param UWSGI_PYHOME /home/pyvirenvs/easonportal; 
> > #uwsgi_param UWSGI_PYHOME /usr/lib64/python2.6; 
> >access_log  off; 
> > } 
> > location /static/ { 
> > root/home/EasonPortal/; 
> > access_log  off; 
> > log_not_found   off; 
> > } 
> >  } 
> > 
> > So, after I start uwsgi and nginx, when access from browser, it raises: 
> > Traceback (most recent call last): 
> >   File "/home/EasonPortal/wsgi.py", line 16, in  
> > from django.core.wsgi import get_wsgi_application 
> > ImportError: No module named django.core.wsgi 
> > 
> > actually, within the py276,