apache配置部署django和php项目


关于apache设置,一台服务器支持多网站多域名,同一域名下也可以访问多个端口

当apache在读取httpd.conf过程中遇到NameVirtuaHost指令时,它为指定的IP地址建立一个虚拟主机表;当apache分析 httpd.conf时,每当它遇见一个<VirtualHost>指令,该指令指定的IP地址与前面分配给虚拟主机驻留的IP地址相同时, 它都在虚拟主机列表上为该IP地址添加虚拟主机;当它找到一个虚拟主机,其  ServerName指令与输入请求的Host头部匹配时,apache就使用该虚拟主机容器中的配置来响应该请求,即使用多个名字指向同一个ip地址。 在本例中,Web主机只拥有一个IP地址(合法地址)200.1.1.1,使用基于主机名称的方式设定多个虚拟主机。

我配置时候出现过很多问题,我的php项目是5.4.45,32位的,Django项目是python36,64位下创建的

使用过:系统win7_64位,windows server 2012 R2_64位,apache2.4_32位,apache2.4_64位,php5.6.40_vc11_32位,php_7.1.26_vc14_64位,php7_vc14_32位,php5.4.45_vc11_32位,python36_64位,python36_32位,mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl,mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win_amd64.whl,

得到结果:因为担心vc环境影响,直接安装编译vc11,vc14. 所有问题与系统位数,django版本没有关系,和apache位数有直接关系。mod_wsgi的位数下载安装时候,一定要和Python环境相对应。php项目版本过低,加载php文件时,无法使用ThinkPHP框架,及无论怎么配置,无法和php7.X配合使用。

成功案例:

apache2.4_64位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win_amd64.whl+python36_64位;

apache2.4_32位+php5.4.45_vc11_32位;

apache2.4_32位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl+python36_32位

apache2.4_32位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl+python36_32位+php5.6.40_vc11_32位

...

下载

下载地址:
http://php.net/

windows版下载地址:
http://windows.php.net/download

官网里Windows的版本有很多。选择哪个版本呢?

如果你的PHP应用程序以FastCGI方式运行,请选择Non-Thread Safe (NTS) 版本;
如果你的PHP应用程序和Apache一起,请选择 Thread Safe (TS) 版本。

本文用的apache+php组合,所以选择ts(Thread Safe)版本。根据操作系统选择x64或者x86。

大多数版本的PHP使用VC9, VC11 or VC14 (Visual Studio 2008, 2012 or 2015分别编译)进行编译的,所以你电脑上需要安装VC运行环境。

电脑需要VC运行环境:


VC9 x86 :http://www.microsoft.com/en-us/download/details.aspx?id=5582


VC9 x64 :http://www.microsoft.com/en-us/download/details.aspx?id=15336


VC11 x86 or x64:http://www.microsoft.com/en-us/download/details.aspx?id=30679


VC14 x86 or x64 :http://www.microsoft.com/en-us/download/details.aspx?id=48145

配置PHP

本文以php-5.6.40-Win32-VC11-x86为例

我是下载之后直接解压到C盘。

1.复制一份php.ini-development文件为php.ini

2.

需要修改以下地方:

  • 更改自定义扩展目录。
    找到
;extension_dir = "ext"

更改为:

 extension_dir = "C:\php-5.6.40-Win32-VC11-x86\ext"

提示:与apache搭配使用需要写绝对位置。否则扩展加载不了。

  • 开启扩展
    往下看,再找到:

去掉部分注释:

extension=php_bz2.dll extension=php_curl.dll extension=php_fileinfo.dll extension=php_gd2.dll extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll extension=php_mbstring.dll extension=php_exif.dll ; Must be after mbstring as it depends on it extension=php_mysql.dll extension=php_mysqli.dll ;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client extension=php_openssl.dll ;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll extension=php_pdo_odbc.dll extension=php_pdo_pgsql.dll extension=php_pdo_sqlite.dll extension=php_pgsql.dll ;extension=php_shmop.dll ; The MIBS data available in the PHP distribution must be installed. ; See http://www.php.net/manual/en/snmp.installation.php ;extension=php_snmp.dll extension=php_soap.dll extension=php_sockets.dll extension=php_sqlite3.dll ;extension=php_sybase_ct.dll extension=php_tidy.dll extension=php_xmlrpc.dll extension=php_xsl.dll
  • 设置默认时区
date.timezone=PRC
  • 设置ssl(可选)
openssl.cafile= cacert.pem

注意是绝对路径。

注意是绝对路径。

  • 添加自定义扩展(根据自己需要)
[memcache] extension=php_memcache.dll [redis] extension=php_redis.dll

注意,需要下载对应版本的扩展:
php_redis-2.2.7-5.6-ts-vc11-x86
区分ts,x86。

下载地址
http://pecl.php.net/package/redis/
http://pecl.php.net/package/memcache
http://pecl.php.net/package/SeasLog
http://pecl.php.net/package/xdebug
http://pecl.php.net/package/yar

apache的安装与配置

下载apache

PHP官网里说明了,apache.org只提供旧的VC6版本,且不能使用 VC9+版本。apache.org已经不提供适合php的版本了。apache windows版本下载地址也给了下载建议:

PHP官网也建议到Apache Lounge下载。Apache Lounge提供了建立在x86和x64系统的VC9,vc14 VC11版本。PHP官方使用了他们提供的二进制文件构建Apache SAPIs。

Apache Lounge提供的下载地址:
http://www.apachelounge.com/download/VC11/

http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.20-win64-VC11.zip
http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.20-win32-VC11.zip

这里选择httpd-2.4.38-win32-VC14.zip

安装配置

把下载好的httpd-2.4.38-win32-VC14.zip的包同样解压到C:/Apache目录下。

接下来,我们来配置apache,让它能够和php协同工作。

进入apache的conf目录,打开apache的配置文件httpd.conf。

修改apache软件所在目录:

ServerRoot "c:/Apache"

修改主机名:

ServerName localhost:80

修改根目录:htdocs是我php文件的根目录

DocumentRoot "C:\myphp\Apache\htdocs" <Directory "C:\myphp\Apache\htdocs">

修改默认索引以支持PHP:

DirectoryIndex index.php index.html index.htm 

开启rewrite功能:

LoadModule rewrite_module modules/mod_rewrite.so

自定义404页面(可选):

ErrorDocument 404 /missing.html

加载PHP模块,注意绝对路径:

LoadModule php5_module C:\php-5.6.40-Win32-VC11-x86/php5apache2_4.dll 
<IfModule php5_module> 
    PHPIniDir "C:/php-5.6.40-Win32-VC11-x86/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

如果是php7,相应更改即可:

#php7
LoadModule php7_module D:/phpsetup/php/php-7.0.13-Win32-VC14-x64/php7apache2_4.dll
<IfModule php7_module> 
    PHPIniDir "D:/phpsetup/php/php-7.0.13-Win32-VC14-x64/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

注意:如果是PHP5.4版本,php目录里只有php5apache2_2.dll,需要和Apache2.2搭配。
所以,安装php5.6一定要确认PHP安装包里是否有php5apache2_4.dll文件。

网上还有一种对于php7的配置方法是(本人没有使用):

  phpinidir "C:/www/php7"
  loadfile "C:/www/php7/php7ts.dll"
  loadfile "C:/www/php7/ssleay32.dll"
  loadfile "C:/www/php7/libeay32.dll"
  loadmodule php7_module "C:/www/php7/php7apache2_4.dll"

  就是多三行代码,引入了3个文件,如果上面方法还是不行,可以试试这个方法,因为php7发布没多长时间,后续这些问题肯定会解决的

可以开启虚拟主机配置文件:

Include conf/extra/httpd-vhosts.conf

默认httpd-vhosts.conf文件里面写的是供参考的,一但启用该文件,请正确配置,否则无法启用apache服务。

虚拟主机示例:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com     #自己邮箱
    DocumentRoot "C:\myphp\Apache\htdocs"            #项目路径
    ServerName example.cn                            #域名
    #erverAlias example.com                           # 别名
    DirectoryIndex index.html                            #主进入口
    ServerAlias www.17ai-trade.cn
    ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log ## 错误日志记录的位置
    CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common # 访问日志的记录位置
</VirtualHost>

其中DocumentRoot设置项目所在路径,ServerName设置主机名,DirectoryIndex设置入口文件;

-----------------------------------------------------------------------------------------------------------------

这部分我没有用,参考文章里面的,

可以开启主机别名配置文件:

Include conf/extra/httpd-alias.conf

如果安装的PHP x64位版本,Apache也需要是x64位版本的。然后还要将php目录下的libeay32.dllssleay32.dlllibssh2.dll以及ext目录下的php_curl.dll等四个文件,都复制放到System32目录下。否则curl扩展无法使用。(http://my.oschina.net/lsfop/blog/496181)

--------------------------------------------------------------------------------------------------------------------

运行apache+php

运行方式一:
手动运行bin目录下的ApacheMonitor.exe

运行方式二:
将apache安装为系统服务,可以开机自动启动。

以管理员权限运行cmd。

进入apache的bin目录,安装Apache 服务:apache24是你起的名字,这个随意起

httpd -k install -n apache24

停止Apache

httpd -k stop apache24 

重启Apache

httpd -k restart

卸载Apache服务

httpd -k uninstall -n apache24 或者sc delete apache24 

测试Apache配置文件httd.conf

httpd -t

查看Apache版本

httpd -V

Apache命令行帮助

httpd -h

删除服务:

sc delete Apache2.4

测试Apache和PHP

成功启动Apache后,在C:\myphp\Apache\htdocs目录编写phpinfo.php:

<?php echo phpinfo();

浏览器地址栏输入localhost/phpinfo.php,显示PHP相关信息即表明成功了。具体问题,后面解答

版本选择总结

Linux下安装推荐编译安装,不用考虑TS、NTS区别。版本建议64位(看机器是否支持)。
PHP7: http://php.net/get/php-7.0.13.tar.bz2/from/a/mirror
php5: http://php.net/get/php-5.6.28.tar.bz2/from/a/mirror
Nginx: http://nginx.org/download/nginx-1.10.2.tar.gz

Windows下安装时注意:

需要先安装VC11或VC14:
1)VC11: https://www.microsoft.com/en-us/download/details.aspx?id=30679
2)VC14: https://www.microsoft.com/en-us/download/details.aspx?id=48145

1、如果使用Apache,请使用TS版本PHP:
PHP7:
1)VC14_x86: http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip
2)VC14_x64:http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip

PHP5:
1)VC11_x86: http://windows.php.net/downloads/releases/php-5.6.28-Win32-VC11-x86.zip
1)VC11_x64: http://windows.php.net/downloads/releases/php-5.6.28-Win32-VC11-x64.zip

Apache:
1、VC14_x64: https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win64-VC14.zip
2、VC14_x86: https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win32-VC14.zip
3、VC11_x64:https://www.apachelounge.com/download/VC11/binaries/httpd-2.4.23-win64-VC11.zip
4、VC11_x86:https://www.apachelounge.com/download/VC11/binaries/httpd-2.4.23-win32-VC11.zip

搭配原则是:VC14+PHP7_TS+Apache_VC14 、VC11+PHP5_TS+Apache_VC11。

2、如果使用Nginx,请使用NTS版本PHP:

PHP7:
1)VC14_x86: http://windows.php.net/downloads/releases/php-7.0.13-nts-Win32-VC14-x86.zip
2)VC14_x64:http://windows.php.net/downloads/releases/php-7.0.13-nts-Win32-VC14-x64.zip

PHP5:
1)VC11_x86: http://windows.php.net/downloads/releases/php-5.6.28-nts-Win32-VC11-x86.zip
1)VC11_x64: http://windows.php.net/downloads/releases/php-5.6.28-nts-Win32-VC11-x64.zip

Nginx: http://nginx.org/download/nginx-1.10.2.zip

安装python及其mod_wsgi

安装python36_32位

网上有很多方式,这里不做叙述,只是需要注意下载和apache版本一致的

安装mod_wsgi

1.注意,因为apache是32位的,所以mod_wsgi也应该选择32位的。mod_wsgi的官网在这里(https://code.google.com/p/modwsgi/)。但是因为没有windows编译版本(自己编译几乎都是以失败告终),所幸在这里可以下载到编译版本(http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi),这里选择mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl

2.将你下载的.whl 文件,放在一个目录中,我放在了 python的 \Scripts 文件夹中,然后 使用cmd cd命令到这个目录

    使用pip 命令进行安装 :pip install mod_wsgi-4.6.4+ap24vc14-cp36-none-win_amd64.whl

注意,现在目录一个在  python的 \Scripts 因为这东西安装完,你会发现在这个目录有一个 mod_wsgi-express.exe 的东西哦

安装完毕之后,执行命令:mod_wsgi-express module-config 

命令执行完毕之后 你会得到以下内容

LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll" LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd" WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"

把这三行目录加载到apache的配置文件当中,即httpd.conf文件中,相当于apache加载mod_wsgi模块。

3.添加监听端口,这里要部署两个项目,一个php一个django,所以设置两个端口:

Listen80

Listen8080

4.打开conf/extra/httpd-vhosts.conf文件,添加对每个项目的参数设置,跟单个项目设置差不多

<VirtualHost *:8080> ServerAdmin webmaster@dummy-host2.example.com ServerName 17ai-trade.cn ServerAlias www.17ai-trade.cn ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common #设置wsgi路径 WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py # 根目录 DocumentRoot "C:/myphp/Apache/mypro" <Directory C:/myphp/Apache/mypro/mypro> <Files wsgi.py> Require all granted </Files> </Directory> #设置静态文件路径 Alias /static C:/myphp/Apache/mypro/static <Directory C:/myphp/Apache/mypro/static> AllowOverride None Options None Require all granted </Directory> #设置根目录 #<Directory "C:/myphp/Apache/mypro"> # Options Indexes FollowSymLinks #AllowOverride None #Require all granted #</Directory> </VirtualHost>

遇到的问题:

demo01:    apache配置php 页面运行完输出php源代码是什么原因

网上说,php没有加载上,也可能php.ini中的配置里面short_open_tag默认是off要改成on才行,我这里都修改过一遍,都不行,最后我把apache跟换成和php版本一致的,32位。才可以访问。

demo02:     You don't have permission to access / on this server

参考:https://blog.csdn.net/qq_21956483/article/details/78732160

demo03:    Cant load modules/mod_wsgi.so

加载模块的方式不对,请参考本文的方式,或查阅更多。

demo04:    解决apache开始时出现的“ (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次” 这个错误

Installing the 'apache' service

The 'apache' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。  : AH00072: mak
e_sock: could not bind to address [::]:443
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。  : AH00072: mak
e_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

方法一: 
      通过 netstat -a -o 查看端口占用情况,关闭调用相关端口的进程。 
c:\> netstat -a -o 

http默认用的是80端口,通过该http协议去查看对应的PID。 
      通过打开“进程管理器”,发现80端口对应的PID=4676的进程号所对应的是迅雷的一个端口号。 
      查看迅雷的端口设置,“配置”→“BT/端口设置”,可以看到TCP端口使用的是 80号端口。点击一下“随机生成”,或者 关闭迅雷。再启动 Apache,一切就OK了。

方法二: 
      通过 修改conf/httpd.conf 中相应的监听端口来处理。 

打开Apache 的配置文件  Apache安装目录下的conf/httpd.conf

找到Listen 80 将80改为 5001

重启Apache访问 http://localhost:5001

方法三:

    我把上面两步全部尝试,最后还是那个问题,最后发觉是我虚拟机的干扰,应该关闭就好,我没尝试,直接卸载了。重启访问,OK。网上有效的解决方式是:

windows下启动apache报make_sock: could not bind to address [::]:443错误!
由于安装了虚拟机VMWare,被占用443端口
解决方法:
打开虚拟机VMware,打开菜单 编辑→首选项(Edit–> Preferences)
点击共享虚拟机后,找到右边的更改设置,点击它
在端口号处,输入444,点击确定,大功告成

demo05:   访问php成功,但访问django是服务无法访问,配置出错,单独访问,不加虚拟主机时,即只在httpd.conf文件配置时,没有问题。查看日志,连续行出现一堆问题,说什么mod_wsgi的问题,原本以为是没有加载这个模块,但单独配置又是可以,猜测是wsgi文件问题,尝试修改了一下,成功。

 

[Fri Jan 25 10:35:29.036672 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] mod_wsgi (pid=3692): Failed to exec Python script file 'C:/myphp/Apache/mypro/mypro/wsgi.py'. [Fri Jan 25 10:35:29.036672 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] mod_wsgi (pid=3692): Exception occurred processing WSGI script 'C:/myphp/Apache/mypro/mypro/wsgi.py'. [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] Traceback (most recent call last):\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "C:/myphp/Apache/mypro/mypro/wsgi.py", line 16, in <module>\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] application = get_wsgi_application()\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "c:\\users\\administrator\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] django.setup(set_prefix=False)\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "<frozen importlib._bootstrap>", line 971, in _find_and_load\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] ModuleNotFoundError: No module named 'mypro'\r

wsgi.py文件中添加以下语句

import sys root = os.path.join(os.path.dirname(__file__), '..') # add parent path sys.path.insert(0, root) # add to sys path

 

 

附加:

apache的配置文件httpd.conf:

  1 #
  2 # This is the main Apache HTTP server configuration file.  It contains the
  3 # configuration directives that give the server its instructions.
  4 # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
  5 # In particular, see 
  6 # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
  7 # for a discussion of each configuration directive.
  8 #
  9 # Do NOT simply read the instructions in here without understanding
 10 # what they do.  They're here only as hints or reminders.  If you are unsure
 11 # consult the online docs. You have been warned.  
 12 #
 13 # Configuration and logfile names: If the filenames you specify for many
 14 # of the server's control files begin with "/" (or "drive:/" for Win32), the
 15 # server will use that explicit path.  If the filenames do *not* begin
 16 # with "/", the value of ServerRoot is prepended -- so "logs/access_log"
 17 # with ServerRoot set to "/usr/local/apache2" will be interpreted by the
 18 # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" 
 19 # will be interpreted as '/logs/access_log'.
 20 #
 21 # NOTE: Where filenames are specified, you must use forward slashes
 22 # instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
 23 # If a drive letter is omitted, the drive on which httpd.exe is located
 24 # will be used by default.  It is recommended that you always supply
 25 # an explicit drive letter in absolute paths to avoid confusion.
 26 
 27 #
 28 # ServerRoot: The top of the directory tree under which the server's
 29 # configuration, error, and log files are kept.
 30 #
 31 # Do not add a slash at the end of the directory path.  If you point
 32 # ServerRoot at a non-local disk, be sure to specify a local disk on the
 33 # Mutex directive, if file-based mutexes are used.  If you wish to share the
 34 # same ServerRoot for multiple httpd daemons, you will need to change at
 35 # least PidFile.
 36 #
 37 Define SRVROOT "c:/Apache"
 38 
 39 ServerRoot "${SRVROOT}"
 40 
 41 #
 42 # Mutex: Allows you to set the mutex mechanism and mutex file directory
 43 # for individual mutexes, or change the global defaults
 44 #
 45 # Uncomment and change the directory if mutexes are file-based and the default
 46 # mutex file directory is not on a local disk or is not appropriate for some
 47 # other reason.
 48 #
 49 # Mutex default:logs
 50 
 51 #
 52 # Listen: Allows you to bind Apache to specific IP addresses and/or
 53 # ports, instead of the default. See also the <VirtualHost>
 54 # directive.
 55 #
 56 # Change this to Listen on specific IP addresses as shown below to 
 57 # prevent Apache from glomming onto all bound IP addresses.
 58 #
 59 #Listen 12.34.56.78:80
 60 Listen 80
 61 Listen 8080
 62 
 63 #
 64 # Dynamic Shared Object (DSO) Support
 65 #
 66 # To be able to use the functionality of a module which was built as a DSO you
 67 # have to place corresponding `LoadModule' lines at this location so the
 68 # directives contained in it are actually available _before_ they are used.
 69 # Statically compiled modules (those listed by `httpd -l') do not need
 70 # to be loaded here.
 71 #
 72 # Example:
 73 # LoadModule foo_module modules/mod_foo.so
 74 #
 75 LoadModule access_compat_module modules/mod_access_compat.so
 76 LoadModule actions_module modules/mod_actions.so
 77 LoadModule alias_module modules/mod_alias.so
 78 LoadModule allowmethods_module modules/mod_allowmethods.so
 79 LoadModule asis_module modules/mod_asis.so
 80 LoadModule auth_basic_module modules/mod_auth_basic.so
 81 #LoadModule auth_digest_module modules/mod_auth_digest.so
 82 #LoadModule auth_form_module modules/mod_auth_form.so
 83 #LoadModule authn_anon_module modules/mod_authn_anon.so
 84 LoadModule authn_core_module modules/mod_authn_core.so
 85 #LoadModule authn_dbd_module modules/mod_authn_dbd.so
 86 #LoadModule authn_dbm_module modules/mod_authn_dbm.so
 87 LoadModule authn_file_module modules/mod_authn_file.so
 88 #LoadModule authn_socache_module modules/mod_authn_socache.so
 89 #LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so
 90 #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
 91 LoadModule authz_core_module modules/mod_authz_core.so
 92 #LoadModule authz_dbd_module modules/mod_authz_dbd.so
 93 #LoadModule authz_dbm_module modules/mod_authz_dbm.so
 94 LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
 95 LoadModule authz_host_module modules/mod_authz_host.so
 96 #LoadModule authz_owner_module modules/mod_authz_owner.so
 97 LoadModule authz_user_module modules/mod_authz_user.so
 98 LoadModule autoindex_module modules/mod_autoindex.so
 99 #LoadModule brotli_module modules/mod_brotli.so
100 #LoadModule buffer_module modules/mod_buffer.so
101 #LoadModule cache_module modules/mod_cache.so
102 #LoadModule cache_disk_module modules/mod_cache_disk.so
103 #LoadModule cache_socache_module modules/mod_cache_socache.so
104 #LoadModule cern_meta_module modules/mod_cern_meta.so
105 LoadModule cgi_module modules/mod_cgi.so
106 #LoadModule charset_lite_module modules/mod_charset_lite.so
107 #LoadModule data_module modules/mod_data.so
108 #LoadModule dav_module modules/mod_dav.so
109 #LoadModule dav_fs_module modules/mod_dav_fs.so
110 #LoadModule dav_lock_module modules/mod_dav_lock.so
111 #LoadModule dbd_module modules/mod_dbd.so
112 #LoadModule deflate_module modules/mod_deflate.so
113 LoadModule dir_module modules/mod_dir.so
114 #LoadModule dumpio_module modules/mod_dumpio.so
115 LoadModule env_module modules/mod_env.so
116 #LoadModule expires_module modules/mod_expires.so
117 #LoadModule ext_filter_module modules/mod_ext_filter.so
118 #LoadModule file_cache_module modules/mod_file_cache.so
119 #LoadModule filter_module modules/mod_filter.so
120 #LoadModule http2_module modules/mod_http2.so
121 #LoadModule headers_module modules/mod_headers.so
122 #LoadModule heartbeat_module modules/mod_heartbeat.so
123 #LoadModule heartmonitor_module modules/mod_heartmonitor.so
124 #LoadModule ident_module modules/mod_ident.so
125 #LoadModule imagemap_module modules/mod_imagemap.so
126 LoadModule include_module modules/mod_include.so
127 #LoadModule info_module modules/mod_info.so
128 LoadModule isapi_module modules/mod_isapi.so
129 #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
130 #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
131 #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
132 #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
133 #LoadModule ldap_module modules/mod_ldap.so
134 #LoadModule logio_module modules/mod_logio.so
135 LoadModule log_config_module modules/mod_log_config.so
136 #LoadModule log_debug_module modules/mod_log_debug.so
137 #LoadModule log_forensic_module modules/mod_log_forensic.so
138 #LoadModule lua_module modules/mod_lua.so
139 #LoadModule macro_module modules/mod_macro.so
140 #LoadModule md_module modules/mod_md.so
141 LoadModule mime_module modules/mod_mime.so
142 #LoadModule mime_magic_module modules/mod_mime_magic.so
143 LoadModule negotiation_module modules/mod_negotiation.so
144 #LoadModule proxy_module modules/mod_proxy.so
145 #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
146 #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
147 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
148 #LoadModule proxy_express_module modules/mod_proxy_express.so
149 #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
150 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
151 #LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
152 #LoadModule proxy_html_module modules/mod_proxy_html.so
153 #LoadModule proxy_http_module modules/mod_proxy_http.so
154 #LoadModule proxy_http2_module modules/mod_proxy_http2.so
155 #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
156 #LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
157 #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
158 #LoadModule ratelimit_module modules/mod_ratelimit.so
159 #LoadModule reflector_module modules/mod_reflector.so
160 #LoadModule remoteip_module modules/mod_remoteip.so
161 #LoadModule request_module modules/mod_request.so
162 #LoadModule reqtimeout_module modules/mod_reqtimeout.so
163 LoadModule rewrite_module modules/mod_rewrite.so
164 #LoadModule sed_module modules/mod_sed.so
165 #LoadModule session_module modules/mod_session.so
166 #LoadModule session_cookie_module modules/mod_session_cookie.so
167 #LoadModule session_crypto_module modules/mod_session_crypto.so
168 #LoadModule session_dbd_module modules/mod_session_dbd.so
169 LoadModule setenvif_module modules/mod_setenvif.so
170 #LoadModule slotmem_plain_module modules/mod_slotmem_plain.so
171 #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
172 #LoadModule socache_dbm_module modules/mod_socache_dbm.so
173 #LoadModule socache_memcache_module modules/mod_socache_memcache.so
174 #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
175 #LoadModule speling_module modules/mod_speling.so
176 #LoadModule ssl_module modules/mod_ssl.so
177 #LoadModule status_module modules/mod_status.so
178 #LoadModule substitute_module modules/mod_substitute.so
179 #LoadModule unique_id_module modules/mod_unique_id.so
180 #LoadModule userdir_module modules/mod_userdir.so
181 #LoadModule usertrack_module modules/mod_usertrack.so
182 #LoadModule version_module modules/mod_version.so
183 #LoadModule vhost_alias_module modules/mod_vhost_alias.so
184 #LoadModule watchdog_module modules/mod_watchdog.so
185 #LoadModule xml2enc_module modules/mod_xml2enc.so
186 
187 <IfModule unixd_module>
188 #
189 # If you wish httpd to run as a different user or group, you must run
190 # httpd as root initially and it will switch.  
191 #
192 # User/Group: The name (or #number) of the user/group to run httpd as.
193 # It is usually good practice to create a dedicated user and group for
194 # running httpd, as with most system services.
195 #
196 User daemon
197 Group daemon
198 
199 </IfModule>
200 
201 # 'Main' server configuration
202 #
203 # The directives in this section set up the values used by the 'main'
204 # server, which responds to any requests that aren't handled by a
205 # <VirtualHost> definition.  These values also provide defaults for
206 # any <VirtualHost> containers you may define later in the file.
207 #
208 # All of these directives may appear inside <VirtualHost> containers,
209 # in which case these default settings will be overridden for the
210 # virtual host being defined.
211 #
212 
213 #
214 # ServerAdmin: Your address, where problems with the server should be
215 # e-mailed.  This address appears on some server-generated pages, such
216 # as error documents.  e.g. admin@your-domain.com
217 #
218 ServerAdmin admin@example.com
219 
220 #
221 # ServerName gives the name and port that the server uses to identify itself.
222 # This can often be determined automatically, but we recommend you specify
223 # it explicitly to prevent problems during startup.
224 #
225 # If your host doesn't have a registered DNS name, enter its IP address here.
226 #
227 ServerName localhost:80
228 
229 #
230 # Deny access to the entirety of your server's filesystem. You must
231 # explicitly permit access to web content directories in other 
232 # <Directory> blocks below.
233 #
234 <Directory />
235     AllowOverride none
236     Require all denied
237 </Directory>
238 
239 #
240 # Note that from this point forward you must specifically allow
241 # particular features to be enabled - so if something's not working as
242 # you might expect, make sure that you have specifically enabled it
243 # below.
244 #
245 
246 #
247 # DocumentRoot: The directory out of which you will serve your
248 # documents. By default, all requests are taken from this directory, but
249 # symbolic links and aliases may be used to point to other locations.
250 #
251 DocumentRoot "C:\myphp\Apache\htdocs"
252 <Directory "C:\myphp\Apache\htdocs">
253     #
254     # Possible values for the Options directive are "None", "All",
255     # or any combination of:
256     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
257     #
258     # Note that "MultiViews" must be named *explicitly* --- "Options All"
259     # doesn't give it to you.
260     #
261     # The Options directive is both complicated and important.  Please see
262     # http://httpd.apache.org/docs/2.4/mod/core.html#options
263     # for more information.
264     #
265     Options Indexes FollowSymLinks
266 
267     #
268     # AllowOverride controls what directives may be placed in .htaccess files.
269     # It can be "All", "None", or any combination of the keywords:
270     #   AllowOverride FileInfo AuthConfig Limit
271     #
272     AllowOverride None
273 
274     #
275     # Controls who can get stuff from this server.
276     #
277     Require all granted
278 </Directory>
279 
280 #
281 # DirectoryIndex: sets the file that Apache will serve if a directory
282 # is requested.
283 #
284 <IfModule dir_module>
285     DirectoryIndex index.html index.htm index.php
286 </IfModule>
287 
288 #
289 # The following lines prevent .htaccess and .htpasswd files from being 
290 # viewed by Web clients. 
291 #
292 <Files ".ht*">
293     Require all denied
294 </Files>
295 
296 #
297 # ErrorLog: The location of the error log file.
298 # If you do not specify an ErrorLog directive within a <VirtualHost>
299 # container, error messages relating to that virtual host will be
300 # logged here.  If you *do* define an error logfile for a <VirtualHost>
301 # container, that host's errors will be logged there and not here.
302 #
303 ErrorLog "logs/error.log"
304 
305 #
306 # LogLevel: Control the number of messages logged to the error_log.
307 # Possible values include: debug, info, notice, warn, error, crit,
308 # alert, emerg.
309 #
310 LogLevel warn
311 
312 <IfModule log_config_module>
313     #
314     # The following directives define some format nicknames for use with
315     # a CustomLog directive (see below).
316     #
317     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
318     LogFormat "%h %l %u %t \"%r\" %>s %b" common
319 
320     <IfModule logio_module>
321       # You need to enable mod_logio.c to use %I and %O
322       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
323     </IfModule>
324 
325     #
326     # The location and format of the access logfile (Common Logfile Format).
327     # If you do not define any access logfiles within a <VirtualHost>
328     # container, they will be logged here.  Contrariwise, if you *do*
329     # define per-<VirtualHost> access logfiles, transactions will be
330     # logged therein and *not* in this file.
331     #
332     CustomLog "logs/access.log" common
333 
334     #
335     # If you prefer a logfile with access, agent, and referer information
336     # (Combined Logfile Format) you can use the following directive.
337     #
338     #CustomLog "logs/access.log" combined
339 </IfModule>
340 
341 <IfModule alias_module>
342     #
343     # Redirect: Allows you to tell clients about documents that used to 
344     # exist in your server's namespace, but do not anymore. The client 
345     # will make a new request for the document at its new location.
346     # Example:
347     # Redirect permanent /foo http://www.example.com/bar
348 
349     #
350     # Alias: Maps web paths into filesystem paths and is used to
351     # access content that does not live under the DocumentRoot.
352     # Example:
353     # Alias /webpath /full/filesystem/path
354     #
355     # If you include a trailing / on /webpath then the server will
356     # require it to be present in the URL.  You will also likely
357     # need to provide a <Directory> section to allow access to
358     # the filesystem path.
359 
360     #
361     # ScriptAlias: This controls which directories contain server scripts. 
362     # ScriptAliases are essentially the same as Aliases, except that
363     # documents in the target directory are treated as applications and
364     # run by the server when requested rather than as documents sent to the
365     # client.  The same rules about trailing "/" apply to ScriptAlias
366     # directives as to Alias.
367     #
368     ScriptAlias /cgi-bin/ "C:\Apache/cgi-bin/"
369 
370 </IfModule>
371 
372 <IfModule cgid_module>
373     #
374     # ScriptSock: On threaded servers, designate the path to the UNIX
375     # socket used to communicate with the CGI daemon of mod_cgid.
376     #
377     #Scriptsock cgisock
378 </IfModule>
379 
380 #
381 # "${SRVROOT}/cgi-bin" should be changed to whatever your ScriptAliased
382 # CGI directory exists, if you have that configured.
383 #
384 <Directory "C:\Apache/cgi-bin">
385     AllowOverride None
386     Options None
387     Require all granted
388 </Directory>
389 
390 <IfModule headers_module>
391     #
392     # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied
393     # backend servers which have lingering "httpoxy" defects.
394     # 'Proxy' request header is undefined by the IETF, not listed by IANA
395     #
396     RequestHeader unset Proxy early
397 </IfModule>
398 
399 <IfModule mime_module>
400     #
401     # TypesConfig points to the file containing the list of mappings from
402     # filename extension to MIME-type.
403     #
404     TypesConfig conf/mime.types
405 
406     #
407     # AddType allows you to add to or override the MIME configuration
408     # file specified in TypesConfig for specific file types.
409     #
410     #AddType application/x-gzip .tgz
411     #
412     # AddEncoding allows you to have certain browsers uncompress
413     # information on the fly. Note: Not all browsers support this.
414     #
415     #AddEncoding x-compress .Z
416     #AddEncoding x-gzip .gz .tgz
417     #
418     # If the AddEncoding directives above are commented-out, then you
419     # probably should define those extensions to indicate media types:
420     #
421     AddType application/x-compress .Z
422     AddType application/x-gzip .gz .tgz
423 
424     #
425     # AddHandler allows you to map certain file extensions to "handlers":
426     # actions unrelated to filetype. These can be either built into the server
427     # or added with the Action directive (see below)
428     #
429     # To use CGI scripts outside of ScriptAliased directories:
430     # (You will also need to add "ExecCGI" to the "Options" directive.)
431     #
432     #AddHandler cgi-script .cgi
433 
434     # For type maps (negotiated resources):
435     #AddHandler type-map var
436 
437     #
438     # Filters allow you to process content before it is sent to the client.
439     #
440     # To parse .shtml files for server-side includes (SSI):
441     # (You will also need to add "Includes" to the "Options" directive.)
442     #
443     #AddType text/html .shtml
444     #AddOutputFilter INCLUDES .shtml
445 </IfModule>
446 
447 #
448 # The mod_mime_magic module allows the server to use various hints from the
449 # contents of the file itself to determine its type.  The MIMEMagicFile
450 # directive tells the module where the hint definitions are located.
451 #
452 #MIMEMagicFile conf/magic
453 
454 #
455 # Customizable error responses come in three flavors:
456 # 1) plain text 2) local redirects 3) external redirects
457 #
458 # Some examples:
459 #ErrorDocument 500 "The server made a boo boo."
460 #ErrorDocument 404 /missing.html
461 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
462 #ErrorDocument 402 http://www.example.com/subscription_info.html
463 #
464 
465 #
466 # MaxRanges: Maximum number of Ranges in a request before
467 # returning the entire resource, or one of the special
468 # values 'default', 'none' or 'unlimited'.
469 # Default setting is to accept 200 Ranges.
470 #MaxRanges unlimited
471 
472 #
473 # EnableMMAP and EnableSendfile: On systems that support it, 
474 # memory-mapping or the sendfile syscall may be used to deliver
475 # files.  This usually improves server performance, but must
476 # be turned off when serving from networked-mounted 
477 # filesystems or if support for these functions is otherwise
478 # broken on your system.
479 # Defaults: EnableMMAP On, EnableSendfile Off
480 #
481 #EnableMMAP off
482 #EnableSendfile on
483 
484 # Supplemental configuration
485 #
486 # The configuration files in the conf/extra/ directory can be 
487 # included to add extra features or to modify the default configuration of 
488 # the server, or you may simply copy their contents here and change as 
489 # necessary.
490 
491 # Server-pool management (MPM specific)
492 #Include conf/extra/httpd-mpm.conf
493 
494 # Multi-language error messages
495 #Include conf/extra/httpd-multilang-errordoc.conf
496 
497 # Fancy directory listings
498 #Include conf/extra/httpd-autoindex.conf
499 
500 # Language settings
501 #Include conf/extra/httpd-languages.conf
502 
503 # User home directories
504 #Include conf/extra/httpd-userdir.conf
505 
506 # Real-time info on requests and configuration
507 #Include conf/extra/httpd-info.conf
508 
509 # Virtual hosts
510 Include conf/extra/httpd-vhosts.conf
511 
512 # Local access to the Apache HTTP Server Manual
513 #Include conf/extra/httpd-manual.conf
514 
515 # Distributed authoring and versioning (WebDAV)
516 #Include conf/extra/httpd-dav.conf
517 
518 # Various default settings
519 #Include conf/extra/httpd-default.conf
520 
521 # Configure mod_proxy_html to understand HTML4/XHTML1
522 <IfModule proxy_html_module>
523 Include conf/extra/proxy-html.conf
524 </IfModule>
525 
526 # Secure (SSL/TLS) connections
527 #Include conf/extra/httpd-ssl.conf
528 #
529 # Note: The following must must be present to support
530 #       starting without SSL on platforms with no /dev/random equivalent
531 #       but a statically compiled-in mod_ssl.
532 #
533 <IfModule ssl_module>
534 SSLRandomSeed startup builtin
535 SSLRandomSeed connect builtin
536 </IfModule>
537 
538 #加载php
539 LoadModule php5_module C:\php-5.6.40-Win32-VC11-x86/php5apache2_4.dll 
540 <IfModule php5_module> 
541     PHPIniDir "C:/php-5.6.40-Win32-VC11-x86/" 
542     AddType application/x-httpd-php .php
543     AddType application/x-httpd-php-source .phps
544 </IfModule>
545 #加载django
546 LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"
547 LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
548 WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"
549 
550 #指定website的wsgi.py配置文件路径  
551 #WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py
552 
553 #指定项目路径  
554 #WSGIPythonPath  C:/myphp/Apache/mypro 
555 #设置wsgi路径 
556 #<Directory C:/myphp/Apache/mypro/mypro>  
557 #<Files wsgi.py>  
558   #  Require all granted  
559 #</Files>  
560 #</Directory>
561 
562 
563 #设置静态文件路径
564 #Alias /static C:/myphp/Apache/mypro/static
565 #<Directory C:/myphp/Apache/mypro/static>  
566  #   AllowOverride None  
567  #   Options None  
568 #    Require all granted  
569 #</Directory> 
httpd.conf

apache的虚拟主机表中的文件httpd-vhosts.conf:

 1 # Virtual Hosts
 2 #
 3 # Required modules: mod_log_config
 4 
 5 # If you want to maintain multiple domains/hostnames on your
 6 # machine you can setup VirtualHost containers for them. Most configurations
 7 # use only name-based virtual hosts so the server doesn't need to worry about
 8 # IP addresses. This is indicated by the asterisks in the directives below.
 9 #
10 # Please see the documentation at 
11 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
12 # for further details before you try to setup virtual hosts.
13 #
14 # You may use the command line option '-S' to verify your virtual host
15 # configuration.
16 
17 #
18 # VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:80>
24     ServerAdmin webmaster@dummy-host.example.com
25     DocumentRoot "C:\myphp\Apache\htdocs"
26     ServerName 17ai-trade.cn
27     DirectoryIndex index.html
28     ServerAlias www.17ai-trade.cn
29     ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log
30     CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common
31 </VirtualHost>
32 
33 <VirtualHost *:8080>
34     ServerAdmin webmaster@dummy-host2.example.com
35     ServerName 17ai-trade.cn
36     ServerAlias www.17ai-trade.cn
37     ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log
38     CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common
39     
40     
41 
42     WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py
43     DocumentRoot "C:/myphp/Apache/mypro"
44     <Directory C:/myphp/Apache/mypro/mypro>  
45         <Files wsgi.py>  
46             Require all granted  
47         </Files>  
48     </Directory>
49 
50 
51     Alias /static C:/myphp/Apache/mypro/static
52     <Directory C:/myphp/Apache/mypro/static>  
53         AllowOverride None  
54         Options None  
55         Require all granted  
56     </Directory>
57     
58     
59     #<Directory "C:/myphp/Apache/mypro">  
60      #   Options Indexes FollowSymLinks
61     #AllowOverride None
62     #Require all granted
63     #</Directory>
64 
65 
66 </VirtualHost>
httpd-vhosts.conf

django中的wsgi.py文件

"""
WSGI config for mypro project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
import sys

root = os.path.join(os.path.dirname(__file__), '..') # add parent path
sys.path.insert(0, root) # add to sys path

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypro.settings")

application = get_wsgi_application()
wsgi.py

 

加载单个php项目:https://www.cnblogs.com/xiezhidong/p/6238379.htmlhttps://www.cnblogs.com/52fhy/p/6059685.html

加载单个django项目:https://blog.csdn.net/weixin_40754816/article/details/80955817

使用phpStudy加载django:https://blog.csdn.net/jklf5/article/details/79531379


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM