由于项目需求,在已有的php项目中,需要跑一个django+mysql的项目,在同一个域名下,想到的办法就是apache反向代理,将域名下的某个链接变为代理。
在ubuntu机器上做一个反向代理的测试,启动一个django的demo,在apache上配置一个反向代理,试试是否可访问;
配置
安装proxy组件
a2enmod proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http
修改配置
sudo vim /etc/apache2/mods-enabled/proxy.conf
<IfModule mod_proxy.c> ???????# If you want to use apache2 as a forward proxy, uncomment the ???????# ‘ProxyRequests On‘ line and the <Proxy *> block below. ???????# WARNING: Be careful to restrict access inside the <Proxy *> block. ???????# Open proxy servers are dangerous both to your network and to the ???????# Internet at large. ???????# ???????# If you only want to use apache2 as a reverse proxy/gateway in ???????# front of some web application server, you DON‘T need ???????# ‘ProxyRequests On‘. ???????ProxyRequests Off ???????<Proxy *> ??????????Require all granted ???????</Proxy> ???????# Enable/disable the handling of HTTP/1.1 "Via:" headers. ???????# ("Full" adds the server version; "Block" removes all outgoing Via: headers) ???????# Set to one of: Off | On | Full | Block ???????#ProxyVia Off</IfModule>
修改apache 虚拟主机配置
<VirtualHost *:80> ???????ServerName ioe1888.com ???????ServerAlias www.ioe1888.com ???????ServerAdmin ioe1888@localhost ???????DocumentRoot /var/www/www.ioe1888.com/ ???????<Directory /> ???????????????Options -Indexes +FollowSymlinks ?????????????????AllowOverride All ?????????????????Require all granted ????????</Directory> ???????<Directory /var/www/www.ioe1888.com/> ???????????????Options -Indexes +FollowSymlinks ?????????????????AllowOverride All ?????????????????Require all granted ????????</Directory> ???????ProxyPass /demo http://127.0.0.1:8000/ ????????ProxyPassReverse /demo http://127.0.0.1:8000/ ????????ErrorLog ${APACHE_LOG_DIR}/ioe1888-site.error.log ???????CustomLog ${APACHE_LOG_DIR}/ioe1888-site.access.log combined</VirtualHost>
在/var/www下建立一个django的demo程序
$ django-admin startproject mysite$ python manage.py migrate$ python manage.py runserver
访问www.ioe1888.com/demo 页面,报错403 ,查看log日志,说的是权限问题
AH01630: client denied by server configuration: proxy:http://127.0.0.1:8000/
修改mysit 目录所属用户和用户组,并给755权限
chown -R www-data:www-data mysite/chmod -R 755 mysite/
继续访问www.ioe1888.com/demo,出现django默认页面
django 配置mysql数据库,需要安装
Django==1.11.5
mysqlclient==1.3.12
pytz==2017.2
requests==2.18.4
urllib3==1.22
DJANGO_SETTINGS_MODULE=‘ieee1888.prd‘ python manage.py runserver django 连接mysql 数据库(ieee1888.prd 换成你自己的)
ubuntu12.04+apache2.4+django 配置反向代理
原文地址:http://www.cnblogs.com/yuguotianqin/p/7659761.html