ubuntu django配置apache2
1.安装apache2.4
sudo apt-get install apache2 libapache2-mod-wsgi -y
2.启动反向代理模块
sudo a2enmod proxy proxy_balancer proxy_http
3.修改apache2的默认编码
sudo sh -c "cat >> /etc/apache2/envars << EOF export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8' EOF"
4.更改apache2配置文件,设置各服务的反向代理
sudo vim /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin xiaobin.wei@deepcam.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
</Directory>
# 代理设置
ProxyRequests Off
ProxyMaxForwards 100
ProxyPreserveHost On
# 统计报表代理
ProxyPass /wdface http://127.0.0.1:8080/wdface
ProxyPassReverse /wdface http://127.0.0.1:8080/wdface
# api接口代理
ProxyPass /api http://127.0.0.1:8081
ProxyPassReverse /api http://127.0.0.1:8081
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
</VirtualHost>
5.配置django通过apache2访问
sudo vim /etc/apache2/sites-available/PythonServiceApi.conf
listen 127.0.0.1:8081
<VirtualHost 127.0.0.1:8081>
ServerAdmin liwu.dong@deepcam.com
ErrorLog ${APACHE_LOG_DIR}/pythonapi-error.log
CustomLog ${APACHE_LOG_DIR}/pythonapi-access.log combined
Alias /data/ /data/
<Directory /data>
Require all granted
</Directory>
DocumentRoot /opt/PythonServiceApi
WSGIScriptAlias / /opt/PythonServiceApi/restApi/wsgi.py
WSGIDaemonProcess pythonapi python-path=/opt/PythonServiceApi
WSGIApplicationGroup %{GLOBAL}
<Directory /opt/PythonServiceApi/restApi>
AddHandler wsgi-script .py
Options +ExecCGI
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
sudo a2ensite PythonServiceApi.conf
sudo service apache2 restart

浙公网安备 33010602011771号