之前用的最多的web框架是LNMP,偶尔也会用到LAMP。接下来简单说下LAMP环境的部署记录,这里选择源码安装的方式:
1)Mysql的安装 部署过程参考:http://www.cnblogs.com/kevingrace/p/6109679.html
2)Apache的安装 依赖软件安装 [root@jenkins-server ~]# yum install gcc gcc-c make wget [root@jenkins-server ~]# yum install zlib-devel openssl-devel [root@jenkins-server ~]# yum install -y perl perl-devel
apr编译安装(下载地址:http://apr.apache.org/download.cgi) [root@jenkins-server ~]# cd /usr/local/src/ [root@jenkins-server src]# wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz [root@jenkins-server src]# tar zxvf apr-1.5.2.tar.gz [root@jenkins-server src]# cd apr-1.5.2 [root@jenkins-server apr-1.5.2]# ./configure --prefix=/usr/local/apache/apr && make && make install
apr-util编译安装(下载地址:http://apr.apache.org/download.cgi) [root@jenkins-server src]# wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz [root@jenkins-server src]# tar zxvf apr-util-1.5.4.tar.gz [root@jenkins-server src]# cd apr-util-1.5.4 [root@jenkins-server apr-util-1.5.4]# ./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/apr [root@jenkins-server apr-util-1.5.4]# make && make install
pcre编译安装 [root@jenkins-server src]# wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz [root@jenkins-server src]# tar zxvf pcre-8.37.tar.gz [root@jenkins-server src]# cd pcre-8.37 [root@jenkins-server pcre-8.37]# ./configure && make && make install
apache编译安装 [root@jenkins-server src]# wget http://www.apache.org/dist/httpd/httpd-2.4.25.tar.gz [root@jenkins-server src]# tar zxvf httpd-2.4.25.tar.gz [root@jenkins-server src]# cd httpd-2.4.25 [root@jenkins-server httpd-2.4.25]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apache/apr/bin/apr-1-config --with-apr-util=/usr/local/apache/apr-util/bin/apu-1-config --enable-module=so --enable-mods-shared=all --enable-deflate --enable-expires --enable-headers --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-mime-magic --enable-authn-dbm --enable-vhost-alias --enable-so --enable-rewrite --enable-ssl --with-mpm=prefork [root@jenkins-server httpd-2.4.25]# makle && make install
配置apache [root@jenkins-server src]# cd /usr/local/apache/conf/ [root@jenkins-server conf]# vim httpd.conf
代码语言:javascript复制........
ServerName localhost:80
........
AddType application/x-compress .Z //这两行是默认就有的,在这两行下面添加下面两行
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php //使apache支持php
AddType application/x-httpd-php-source .php5
......
LoadModule php5_module modules/libphp5.so //添加php模块,这个在后面php编译安装后就会自动加进来。最后一定要检查这里是否有php模块产生
......
DocumentRoot "/var/www/html" //修改apache站点目录路径,默认是/usr/local/apache/htdocs
<Directory "/var/www/html">
.......
Include conf/extra/mxwang.conf //添加虚拟主机配置文件
[root@jenkins-server conf]# cd extra/ [root@jenkins-server extra]# vim mxwang.conf <VirtualHost *:80> ServerName www.mxwang.cn DocumentRoot /var/www/html ErrorLog "/var/log/httpd/www.mxwang.cn-error_log" CustomLog "/var/log/httpd/www.mxwang.cn-access_log" common
</VirtualHost>
启动apache [root@jenkins-server extra]# /usr/local/apache/bin/httpd [root@jenkins-server extra]# ps -ef|grep http root 30145 1 2 19:53 ? 00:00:00 /usr/local/apache/bin/httpd nobody 30146 30145 0 19:53 ? 00:00:00 /usr/local/apache/bin/httpd nobody 30147 30145 0 19:53 ? 00:00:00 /usr/local/apache/bin/httpd nobody 30148 30145 0 19:53 ? 00:00:00 /usr/local/apache/bin/httpd nobody 30149 30145 0 19:53 ? 00:00:00 /usr/local/apache/bin/httpd nobody 30150 30145 0 19:53 ? 00:00:00 /usr/local/apache/bin/httpd root 30156 2090 0 19:53 pts/3 00:00:00 grep --color http
[root@jenkins-server extra]# cat /var/www/html/test.html sdfasdfasdf
测试访问:http://www.mxwang.cn/test.html
3)PHP编译安装 [root@jenkins-server ~]# yum install libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel net-snmp net-snmp-devel [root@jenkins-server ~]# cd /usr/local/src/ [root@jenkins-server src]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz [root@jenkins-server src]# tar zxvf libiconv-1.14.tar.gz [root@jenkins-server src]# cd libiconv-1.14 [root@jenkins-server libiconv-1.14]# ./configure --prefix=/usr/local/php/libiconv && make && make install
[root@jenkins-server src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz [root@jenkins-server src]# tar zxvf libmcrypt-2.5.8.tar.gz [root@jenkins-server src]# cd libmcrypt-2.5.8 [root@jenkins-server libmcrypt-2.5.8]# ./configure && make && make install [root@jenkins-server libmcrypt-2.5.8]# /sbin/ldconfig && cd libltdl/ [root@jenkins-server libltdl]# ./configure --enable-ltdl-install && make && make install
[root@jenkins-server src]# wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz [root@jenkins-server src]# tar zxvf mhash-0.9.9.9.tar.gz [root@jenkins-server src]# cd mhash-0.9.9.9 [root@jenkins-server mhash-0.9.9.9]# ./configure && make && make install
[root@jenkins-server src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz [root@jenkins-server src]# tar zxvf mcrypt-2.6.8.tar.gz [root@jenkins-server src]# cd mcrypt-2.6.8 [root@jenkins-server mcrypt-2.6.8]# /sbin/ldconfig && export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH [root@jenkins-server mcrypt-2.6.8]# ./configure && make && make install
[root@jenkins-server src]# wget http://cn2.php.net/distributions/php-5.6.15.tar.gz [root@jenkins-server src]# tar zxvf php-5.6.15.tar.gz [root@jenkins-server src]# cd php-5.6.15 [root@jenkins-server php-5.6.15]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-iconv=/usr/local/php/libiconv --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-png-dir --with-pear --with-freetype-dir --with-zlib --with-libxml-dir --with-iconv-dir --with-xmlrpc --with-mhash --with-mcrypt --with-curl --with-openssl --with-snmp --with-gettext --enable-pdo --enable-mbstring --enable-ctype --enable-simplexml --enable-ftp --enable-sockets --enable-gd-native-ttf --enable-sysvsem --enable-exif --enable-sysvshm --enable-xml --enable-dom --enable-simplexml --enable-shmop --enable-zip --enable-mbregex --enable-bcmath --enable-inline-optimization --enable-soap [root@jenkins-server php-5.6.15]# make && make install [root@jenkins-server php-5.6.15]# cp php.ini-production /usr/local/php/etc/php.ini [root@jenkins-server php-5.6.15]# vim /etc/profile ...... export PATH=$PATH:/usr/local/php/bin [root@jenkins-server php-5.6.15]# source /etc/profile
[root@jenkins-server src]# /usr/local/php/bin/php -m [PHP Modules] bcmath Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext hash iconv json libxml mbstring mcrypt mhash mysql mysqli mysqlnd openssl pcre PDO pdo_mysql pdo_sqlite Phar posix Reflection session shmop SimpleXML snmp soap sockets SPL sqlite3 standard sysvsem sysvshm tokenizer xml xmlreader xmlrpc xmlwriter zip zlib
[Zend Modules]
一定要记得重启aapche [root@jenkins-server src]# pkill -9 http [root@jenkins-server src]# ps -ef|grep http root 31091 12736 0 20:06 pts/6 00:00:00 grep --color http [root@jenkins-server src]# /usr/local/apache/bin/httpd [root@jenkins-server src]# ps -ef|grep http root 31098 1 7 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31099 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31100 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31101 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31102 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31103 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd root 31106 12736 0 20:06 pts/6 00:00:00 grep --color http
测试php: [root@jenkins-server src]# cat /var/www/html/test.php <?php phpinfo() ?>
访问:www.mxwang.cn/test.php
注意几点: php.ini文件中的设置时区 [root@jenkins-server src]# vim /usr/local/php/etc/php.ini ...... date.timezone = PRC
保证站点目录下的文件权限和apache启动用户一致: [root@jenkins-server src]# ps -ef|grep http root 31098 1 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31099 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31100 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31101 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31102 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31103 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd nobody 31151 31098 0 20:06 ? 00:00:00 /usr/local/apache/bin/httpd root 31409 12736 0 20:10 pts/6 00:00:00 grep --color http [root@jenkins-server src]# ll /var/www/html/ total 40232 drwxr-xr-x. 3 777 nobody 4096 Jan 5 12:47 addons -rw-r--r--. 1 777 nobody 464 Jan 5 12:47 admin.php drwxr-xr-x. 2 777 nobody 4096 Jan 5 12:47 api -rw-r--r--. 1 777 nobody 216 Jan 5 12:47 api.php ......
可以将上面的安装过程归档在一个安装脚本里进行一键安装
-------------------------------------------------------------------------apache下http强制转https配置--------------------------------------------------------------
代码语言:javascript复制1)在httpd.conf文件里使下面模块生效
[root@back ~]# cat /usr/local/apache/conf/httpd.conf|grep rewrite_module
.......
LoadModule rewrite_module modules/mod_rewrite.so
2)httpd.conf配置文件或者是在httpd-vhost.conf文件里修改
[root@back ~]# cat /usr/local/apache/conf/httpd.conf
.......
DocumentRoot "/data/vhosts"
<Directory "/data/vhosts">
Options FollowSymLinks MultiViews Includes
AllowOverride All
Require all granted
</Directory>
3)在网站根目录下面添加该文件“.htaccess” 目录访问控制文件,并添加如下内容:
#---------------------------------
RewriteEngine on #开启重定向引擎
RewriteBase / #可以不设置
RewriteCond %{SERVER_PORT} !^443$ #非443端口的数据全部进行重定向
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] #把需要重定向的内容重定向到https
#----------------------------------
.htaccess文件不能在win平台下自己创建,可以使用下面链接在线生成该文件:http://www.wangqu.org/htaccess/#a_WWW
#----------------------------------
RewriteEngine on #开启重定向引擎
RewriteBase / #可以不设置
RewriteCond %{SERVER_PORT} !^443(或者其他端口)$ #非443端口的数据全部进行重定向
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] #把需要重定向的内容重定向到https
#如果是默认不是443端口,那么可以在最后一行写成这样
RewriteRule ^.*$ https://www.wang.com:8443
#当然如果默认是443的话,也可以这么写
RewriteRule ^.*$ https://www.wang.com
#该 .htaccess 需要放置在网站的根目录下面才可以生效
#----------------------------------
含义是这样的:为了让用户访问传统的http://转到https://上来,用了一下rewrite规则:
第一句:启动rewrite引擎
第二句:rewrite的条件是访问的服务器端口不是443端口
第三句:这是正则表达式,^是开头,$是结束,/?表示有没有/都可以(0或1个),(.*)是任何数量的任意字符
整句的意思是讲:启动rewrite模块,将所有访问非443端口的请求,url地址内容不变,将http://变成https://。
------------------------------------------------------------------------------------------------------------------------------------------- 看看下面一例:
代码语言:javascript复制[root@back ~]# cat /usr/local/apache/conf/httpd.conf|grep -v "#"|grep -v "^$"
ServerRoot "/usr/local/apache"
Listen 80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
<IfModule unixd_module>
User nobody
Group nobody
</IfModule>
ServerAdmin you@example.com
ServerName www.example.com:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/data/vhosts"
<Directory "/data/vhosts">
Options FollowSymLinks MultiViews Includes
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml .php3 .inc
AddType application/x-httpd-php-source .phps
</IfModule>
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
[root@back ~]# cd /usr/local/apache/conf
[root@back conf]# ls
wang.cer extra httpd.conf.bak httpd_orig.conf mime.types server.crt server.key
wang.key httpd.conf httpd.conf-orig magic original server.csr server.key.unsecure
[root@back conf]# cd extra/
[root@back extra]# ls
httpd-autoindex.conf httpd-languages.conf httpd-ssl.conf httpd-userdir.conf
httpd-dav.conf httpd-manual.conf httpd-ssl.conf.bak httpd-vhosts.conf
httpd-default.conf httpd-mpm.conf httpd-ssl.conf-orig httpd-vhosts.conf-orig
httpd-info.conf httpd-multilang-errordoc.conf httpd-ssl_orig.conf proxy-html.conf
[root@back extra]# cat httpd-vhosts.conf |grep -v "#"|grep -v "^$"
<Directory "/data/vhosts/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/limesurvey/"
ServerName wj.wang.com
ErrorLog "logs/limesurvey.wang.com-error_log"
CustomLog "logs/limesurvey.wang.com-access_log" combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/nextcloud/"
ServerName nextcloud.wang.com
ErrorLog "logs/nextcloud.wang.com-error_log"
CustomLog "logs/nextcloud.wang.com-access_log" combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/opensns/"
ServerName opensns.wang.com
ErrorLog "logs/opensns.wang.com-error_log"
CustomLog "logs/opensns.wang.com-access_log" combined
<Directory "/data/vhosts/opensns/">
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/discuz/"
ServerName discuz.wang.com
ErrorLog "logs/discuz.wang.com-error_log"
CustomLog "logs/discuz.wang.com-access_log" combined
</VirtualHost>
[root@back extra]# cat httpd-ssl.conf |grep -v "#"|grep -v "^$"
Listen 0.0.0.0:443
SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLHonorCipherOrder on
SSLProtocol all -SSLv3
SSLProxyProtocol all -SSLv3
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:/usr/local/apache/logs/ssl_scache(512000)"
SSLSessionCacheTimeout 300
<VirtualHost *:443>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/limesurvey/"
ServerName limesurvey.wang.com
SSLEngine on
SSLCertificateFile "/usr/local/apache/conf/wang.cer"
SSLCertificateKeyFile "/usr/local/apache/conf/wang.key"
ErrorLog "logs/limesurvey.wang.com-https-error_log"
CustomLog "logs/limesurvey.wang.com-https-access_log" combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/opensns/"
ServerName opensns.wang.com
SSLEngine on
SSLCertificateFile "/usr/local/apache/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server.key"
ErrorLog "logs/opensns.wang.com-https-error_log"
CustomLog "logs/opensns.wang.com-https-access_log" combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/nextcloud/"
ServerName nextcloud.wang.com
SSLEngine on
SSLCertificateFile "/usr/local/apache/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server.key"
ErrorLog "logs/nextcloud.wang.com-https-error_log"
CustomLog "logs/nextcloud.wang.com-https-access_log" combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/discuz/"
ServerName discuz.wang.com
SSLEngine on
SSLCertificateFile "/usr/local/apache/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server.key"
ErrorLog "logs/opensns.wang.com-https-error_log"
CustomLog "logs/opensns.wang.com-https-access_log" combined
</VirtualHost>
<VirtualHost _default_:443>
DocumentRoot "/data/vhosts"
ServerName test.com
ServerAdmin g-ops-all@wang.com
ErrorLog "/usr/local/apache/logs/discuz-https-error_log"
TransferLog "/usr/local/apache/logs/discuz-https-access_log"
SSLEngine on
SSLCertificateFile "/usr/local/apache/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server.key"
<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions StdEnvVars
</FilesMatch>
<Directory "/usr/local/apache/cgi-bin">
SSLOptions StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]"
nokeepalive ssl-unclean-shutdown
downgrade-1.0 force-response-1.0
CustomLog "/usr/local/apache/logs/ssl_request_log"
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"
</VirtualHost>
http强制跳转到https,在每个站点的根目录下添加.htaccess文件,配置如下:
[root@back ~]# cat /data/vhosts/limesurvey/.htaccess.bak
<IfModule mod_rewrite.c>
RewriteEngine on
# RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
# General setting to properly handle LimeSurvey paths
# AcceptPathInfo on
这样,访问http://limesurvey.wang.com就会强制跳转为https://limesurvey.wang.com。 其他域名配置一样!
------------------------------------------------------------------------apache下多端口虚拟主机配置----------------------------------------------------------------------
代码语言:javascript复制apache服务器上(apache php)配置三个域名zpadmin.wang.com、 zpwechat.wang.com、zpimages.wang.com
然后在前面LB层进行反向代理配置(apache真实服务器没有外网ip)
三个域名分别对应三个端口8080、8081、8082,注意http.conf文件里的Listen
[root@localhost ~]# cat /data/apache/conf/httpd.conf|grep -v "#"|grep -v "^$"
ServerRoot "/data/apache"
Listen 192.168.1.32:8080
Listen 192.168.1.32:8081
Listen 192.168.1.32:8082
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
<IfModule unixd_module>
User nobody
Group nobody
</IfModule>
ServerAdmin you@example.com
ServerName www.example.com:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/data/vhosts"
<Directory "/data/vhosts">
Options FollowSymLinks MultiViews Includes
AllowOverride All
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/data/apache/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/data/apache/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml .php3 .inc
AddType application/x-httpd-php-source .phps
</IfModule>
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
虚拟主机配置如下:
注意,Apache2.4.x版本版本后就取消了NameVirtualHost配置。
所以配置对应端口的虚拟主机时不需要在<VirtualHost 192.168.1.32:8080>的前面再设置 NameVirtualHost 192.168.1.32:8080了
[root@localhost ~]# cat /data/apache/conf/extra/httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
# <VirtualHost 192.168.1.32:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "/data/apache/docs/dummy-host.example.com"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
# </VirtualHost>
# <VirtualHost 192.168.1.32:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot "/data/apache/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
# </VirtualHost>
# =============================================================
# Add by Francis Hao @ 2017-06-27
<Directory "/data/vhosts/">
Options FollowSymLinks
# Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
<VirtualHost 192.168.1.32:8080>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/shellking/backend/web"
ServerName zpadmin.wang.com
ErrorLog "logs/zpadmin-error_log"
CustomLog "logs/zpadmin-access_log" combined
</VirtualHost>
<VirtualHost 192.168.1.32:8081>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/shellking/wechat/web"
ServerName zpwechat.wang.com
ErrorLog "logs/zpwechat-error_log"
CustomLog "logs/zpwechat-access_log" combined
</VirtualHost>
<VirtualHost 192.168.1.32:8082>
ServerAdmin g-ops-all@wang.com
DocumentRoot "/data/vhosts/shellking/upload"
ServerName zpimages.wang.com
ErrorLog "logs/zpimages-error_log"
CustomLog "logs/zpimages-access_log" combined
</VirtualHost>
前面LB层的反向代理配置:
[root@nginx-web01 ~]# cat /data/nginx/conf/vhosts/zpadmin.conf
upstream zpadmin {
server 192.168.1.32:8080 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
server_name zpadmin.wang.com;
access_log logs/zpadmin_access.log main;
error_log logs/zpadmin_error.log;
location / {
proxy_pass http://zpadmin/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
[root@nginx-web01 ~]# cat /data/nginx/conf/vhosts/zpwechat.conf
upstream zpwechat {
server 192.168.1.32:8081 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
server_name zpwechat.wang.com;
access_log logs/zpwechat_access.log main;
error_log logs/zpwechat_error.log;
location / {
proxy_pass http://zpwechat/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
[root@nginx-web01 ~]# cat /data/nginx/conf/vhosts/zpimages.conf
upstream zpimages {
server 192.168.1.32:8082 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
server_name zpimages.wang.com;
access_log logs/zpimages_access.log main;
error_log logs/zpimages_error.log;
location / {
proxy_pass http://zpimages/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}