apache虚拟主机

一.Apache配置

1.安装apache package

yum install httpd httpd-devel -y

2.安装 mod_wsgi for python3

pip3 install mod_wsgi

3.导出apache所需的mod_wsgi模块

mod_wsgi-express install-module
会返回下面内容(依据个人环境):
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

WSGIPythonHome "/var/www/html/.py3env"

4.配置apache httpd.conf配置文件

vim /etc/httpd/conf/httpd.conf

1.打开Listen 80 # 你需要监听的端口
2.在Include conf.modules.d/*.conf下面添加下面一行
Include conf/extra/*.conf
3.设置ServerName 0.0.0.0:80
4.末行添加:
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"

5.配置apache httpd-vhosts.conf

  • 1.cd /etc/httpd/conf

  • 2.mkdir extra

  • 3.cd extra

  • 4.vim httpd-vhosts.conf


    ServerAdmin [email protected]
    ServerName www.eee.com
    #ServerAlias www.aaa.com
    ErrorLog /opt/logs/error_django.log
    CustomLog /opt/logs/access_django.log common

    #设置wsgi路径
    WSGIScriptAlias / /opt/wxbox/wxbox/wsgi.py
    # 根目录
    DocumentRoot "/opt/wxbox"
    
        
            Require all granted
        
    

    #设置静态文件路径
    Alias /static /opt/wxbox/static
    
        Order deny,allow
        Allow from all
        Require all granted
    

    #设置根目录
    
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
    



    ServerAdmin [email protected]
    ServerName www.ggg.com
    #ServerAlias www.aaa.com
    ErrorLog /opt/logs/error_django.log
    CustomLog /opt/logs/access_django.log common

    #设置wsgi路径
    WSGIScriptAlias / /opt/test/wxbox/wxbox/wsgi.py
    # 根目录
    DocumentRoot "/opt/test/wxbox"
    
        
            Require all granted
        
    

    #设置静态文件路径
    Alias /static /opt/test/wxbox/static
    
        Order deny,allow
        Allow from all
        Require all granted
    

    #设置根目录
    
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
    

6.修改wsgi.py文件

import os, sys

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wxbox.settings")
sys.path.append('/opt/wxbox') #增加这一行

application = get_wsgi_application()

7.启动apache

systemctl restart httpd

你可能感兴趣的:(apache虚拟主机)