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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步