因爲項目需求,在已有的php項目中,須要跑一個django+mysql的項目,在同一個域名下,想到的辦法就是apache反向代理,將域名下的某個連接變爲代理。php
在ubuntu機器上作一個反向代理的測試,啓動一個django的demo,在apache上配置一個反向代理,試試是否可訪問;python
配置mysql
安裝proxy組件web
a2enmod proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http
修改配置sql
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程序apache
$ django-admin startproject mysite $ python manage.py migrate $ python manage.py runserver
訪問www.ioe1888.com/demo 頁面,報錯403 ,查看log日誌,說的是權限問題django
AH01630: client denied by server configuration: proxy:http://127.0.0.1:8000/
修改mysit 目錄所屬用戶和用戶組,並給755權限ubuntu
chown -R www-data:www-data mysite/ chmod -R 755 mysite/
繼續訪問www.ioe1888.com/demo,出現django默認頁面vim
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 換成你本身的)