附:httpd.conf
ServerName www.xu.com:80
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
#指定myweb项目的wsgi.py配置文件路径
WSGIScriptAlias / /opt/web/webapp/wsgi.py
#指定项目路径
WSGIPythonPath /opt/web/webapp/wsgi.py
<Directory /opt/web/webapp>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
Apache版本:Server version: Apache/2.2.22 (Ubuntu)
附:sites-available/sitename.conf
sites-available# cat sitename.conf
<VirtualHost *:80>
Alias /media/ /opt/***/web/www/
Alias /static/ /opt/***/web/www/
<Directory /opt/***/web/www/>
Order deny,allow
Allow from all
</Directory>
<Directory /opt/***/web/webapp/>
<Files wsgi.py>
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Files>
</Directory>
</VirtualHost>
1.apt-get
install
apache2 libapache2-mod-wsgi
命令:
service apache2 reload
/etc/init.d/apache2 restart
find / -name httpd.conf
查看日志:tail -n 50 -f /var/log/apache2/error.log
service apache2 restart
启动报错:ValueError: Unable to configure handler 'filelog': [Errno 13] Permission denied: '/var/log/www/webapp.log'
解决:1.改权限 chmod 775 /var/log/www/webapp.log-----》
2.查看Apache用户 #ps aux|grep apache root 19025 0.0 0.0 7196 612 pts/1 S+ 15:39 0:00 tail -n 50 -f /var/log/apache2/error.log root 20241 0.0 0.1 91016 3576 ? Ss 17:00 0:00 /usr/sbin/apache2 -k start www-data 20244 0.0 0.1 90748 2692 ? S 17:00 0:00 /usr/sbin/apache2 -k start www-data 20246 0.0 0.9 454940 20040 ? Sl 17:00 0:00 /usr/sbin/apache2 -k start www-data 20247 0.0 0.9 454940 20040 ? Sl 17:00 0:00 /usr/sbin/apache2 -k start root 20316 0.0 0.0 9384 944 pts/2 S+ 17:15 0:00 grep --color=auto apache
----》
3.更改用户: chown www-data /var/log/www/webapp.log
报错:ImproperlyConfigured: Error importing middleware jango.authx: "No module named jango.authx
暂时解决:
与Django的搜索路径与Import机制有关:添加相应的(此处是jango.authx)所在路径sys.path.append("/opt/***/lib/python")
报错:
1 lne 86, in __init__ 2 rotatingHandler.doRollover() 3 File "/lib/python2.7/lib/logging/handlers.py", line 131, in doRollover 4 os.rename(self.baseFilename, dfn) 5 OSError: [Errno 13] Permission denied
暂时解决: 1、找到logging库下的handlers.py文件,定位到RotatingFileHandler的基类的doRollover方法,修改如下代码:
~用户root权限1 try: 2 os.rename(self.baseFilename, dfn) 3 #记得先import shutil,替换为: 4 try: 5 shutil.move(self.baseFilename, dfn)
未完待续修改/etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示: ## Allow root to run any commands anywhere root ALL=(ALL) ALLwww-data ALL=(ALL) ALL日志和资源权限问题的解决:将项目文件夹webapp和资源文件夹www复制到一个部署文件夹,更改文件夹权限chown为www-data。将httpd.conf里的相应配置指向部署文件夹。