美文网首页
apache虚拟主机

apache虚拟主机

作者: 火鸡不肥 | 来源:发表于2019-08-01 16:25 被阅读0次

一.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

<VirtualHost *:80>
    ServerAdmin huojibufei@gmail.com
    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"
    <Directory /opt/wxbox/wxbox>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

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

    #设置根目录
    <Directory "/opt/wxbox">
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin huojibufei@gmail.com
    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"
    <Directory /opt/test/wxbox/wxbox>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

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

    #设置根目录
    <Directory "/opt/test/wxbox">
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
    </Directory>
</VirtualHost>

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虚拟主机

      本文链接:https://www.haomeiwen.com/subject/unkcdctx.html