Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico
Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/
<Directory /path/to/mysite.com/static>
Require all granted
</Directory>
<Directory /path/to/mysite.com/media>
Require all granted
</Directory>
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
AddType text/html .py
WSGISocketPrefix /var/run/
</IfModule>
当然也可以将相关的配置写在虚拟主机的配置中。
apache配置文件:虚拟主机的配置参数(略)
mod_wgsi配置过程中可能遇到的问题:
5xx服务器内部错误
这种问题可以通过检查apache的错误文件发现问题,错误文件/var/log/httpd/error.log中出现类似于 mod_wsgi (pid=20380): Target WSGI script '/var/www/test0/test0/wsgi.py' cannot be loaded as Python module.
问题很可能出在所安装的mod_wsgi扩展没有找到相应的链接库。
解决方法:
1.检查python编译安装要安装共享库
./configure --enabled-shared
make && make install
2.添加共享库到路径
sudo vi /etc/ld.so.conf
/usr/local/Python2.7/lib
sudo /sbin/ldconfig -v
3.使用编译安装mod_wsgi
./configure --with-apxs=/usr/local/apache/bin/apxs \
--with-python=/usr/local/bin/python
报错:Permission denied: mod_wsgi (pid=2081): Unable to connect to WSGI daemon process 'autotester' on '/etc/httpd/logs/wsgi.2076.0.1.sock' after multiple attempts
可在apache配置文件或者wsgi.conf中添加
WSGISocketPrefix /var/run/
来自 <https://my.oschina.net/crazyharry/blog/336811>
使用.configure --enable-shared 安装python2.7之后出现下面的报错:
error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
解决方法如下:
来自 <http://blog.csdn.net/wanyanxgf/article/details/8021641>
1.编辑 vi /etc/ld.so.conf
如果是非root权限帐号登录,使用 sudo vi /etc/ld.so.conf
添加上python2.7的lib库地址,如我的/usr/local/Python2.7/lib,保存文件
2.执行 /sbin/ldconfig -v命令,如果是非root权限帐号登录,使用 sudo /sbin/ldconfig -v。这样 ldd 才能找到这个库,执行python2.7就不会报错了
/etc/ld.so.conf:
这个文件记录了编译时使用的动态链接库的路径。
默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件
如果你安装了某些库,没有指定 --prefix=/usr 这样lib库就装到了/usr/local下,而又没有在/etc/ld.so.conf中添加/usr/local/lib,就会报错了
ldconfig是个什么东东吧 :
它是一个程序,通常它位于/sbin下,是root用户使用的东东。具体作用及用法可以man ldconfig查到
简单的说,它的作用就是将/etc/ld.so.conf列出的路径下的库文件 缓存到/etc/ld.so.cache 以供使用
因此当安装完一些库文件,(例如刚安装好glib),或者修改ld.so.conf增加新的库路径后,需要运行一下/sbin/ldconfig
使所有的库文件都被缓存到ld.so.cache中,如果没做,即使库文件明明就在/usr/lib下的,也是不会被使用的,结果编译过程中抱错,缺少xxx库。