ubuntu12.04+apache2.4+django 配置反向代理

由于项目需求,在已有的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 换成你自己的)

转载于:https://www.cnblogs.com/yuguotianqin/p/7659761.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值