对于新手来说一个很大的问题就是连源码包都在到在哪下载,还有就是软件的依赖关系
如果网卡也不会配置,请翻看我的其他文章
这就是基本所需的源码包了
http://pan.baidu.com/s/1kTxbN5X
然后就是开始
yum -y install gcc gcc-c++ autoconf nss_ldap libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers pcre pcre-devel make wget vim cmake gd gd-devel libevent libevent-devel zip unzip libtool
yum基本的rpm包
安装完成之后
关闭selinux和防火墙
service iptables stop
chkconfig iptables off
vi /etc/selinux/config
把SELINUX=enforcing 修改为disabled
centos7是iptables被firewalld替代了
systemctl stop firewalld
记得改完之后reboot重启或者直接service iptables restart
源码存放路径:/usr/local/src
yum install lrzsz
cd /usr/local/src
rz
可以多选
这个虚拟机比较方便,如果是真机器上,装完系统之后直接wget到src文件里就行
tar -zxvf 源码包
安装httpd
首先安装apr
tar -zxvf apr-1.5.1.tar.gz
cd apr-1.5.1
./configure --prefix=/usr/local/apr
如果你不知道是不是对的,请直接继续,如果在编译httpd有问题可以删掉文件夹,再次编译,没事
make && make install
cd ..
tar -zxvf apr-util-1.5.4.tar.gz
cd cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
tar -zxvf httpd-2.4.10.tar.gz
cd httpd-2.4.10
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-most-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
配置文件在 /etc/httpd/httpd.conf
make && make install
cd /usr/local/apache
bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
如果出现以下问题
vi /etc/httpd/httpd.conf
首先把pid文件指到run下面,这个和出现的问题无关
在serveRoot="/usr/local/apche" apache的根目录加上。如果USR目录空间不大,可以吧目录指导HOME目录下
PidFile "/var/run/httpd.pid"
配置而已
找ServerName和ServerAdmin改成
ServerAdmin localhost
ServerName localhost:80
ESC
:wq保存退出
netstat -tnlp
kill 80断就的PID
cd /usr/local/apache
bin/apachectl start
curl 127.0.0.1
It works!、
在别的机器上输入IP,就OK了
网站根目录/usr/local/apache/htdocs 下面index.html就是主页文件
吧httpd加入开机启动
1、将apachectl文件拷贝到/etc/rc.d/init.d 中,然后在/etc/rc.d/rc5.d/下加入链接即可。
命令如下:
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd //如果有其他的版本的Apache存在,也可以直接覆盖掉
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd //建立链接(85的意义后面介绍)
此时Apache就可以自动启动了。
2、 运行chkconfig --list,发现没有linux服务列表中httpd,通过chkconfig --add httpd来添加,但是提示:httpd服务不支持 chkconfig。需要编辑/etc/rc.d/init.d/httpd,添加以下注释信息:任何位置都可以
# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server
第一行3个数字参数意义分别为:哪些Linux级别需要启动httpd(3,4,5);启动序号(85);关闭序号(15)。
保存后执行:chkconfig --add httpd,成功添加。
在rc3.d、rc4.d、rc5.d路径中会出现S85httpd的链接文件,其他运行级别路径中会出现K61httpd的链接文件。
3、运行chkconfig --list httpd
接下来是mysql
这就有个大问题,大文件的mysql源码包是无法使用rz命令,这里有个小技巧
你平常用的ftp工具 除了登陆ftp之外,还是可以用root用户登陆选择sftp over ssh这个就可以用root用户登陆,大文件就可以上传了,不用安装samba和配置
cp /root/mysql-5.6.21-x86_64.tar.gz /usr/local/
tar -zxvf mysql-5.6.21-x86_64.tar.gz
创建软链接
创建用户组合用户id
groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql
id mysql
chown -R mysql.mysql /usr/local/mysql/*
更改属组
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
mkdir -p /usr/local/mysql
tar zxvf mysql-5.5.28.tar.gz
cd mysql-5.5.28
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
根据自己需求编译选项
make
make install
cd /usr/local/mysql
cp ./support-files/my-medium.cnf /etc/my.cnf
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
chown -R mysql.mysql /data/mysql/data
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chkconfig --list mysqld
vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql/
datadir=/data/mysql/data/
加上
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile 吧mysql的命令加入
source /etc/profile 启动命令
ln -s /usr/local/mysql/lib/mysql /usr/local/lib64/mysql
ln -s /usr/local/mysql/include/mysql /usr/local/include/mysql
service mysqld start
mysql -uroot 登陆 默认密码为空
mysql> SET PASSWORD = PASSWORD('123456'); 设置root密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
开始远程访问
初始化的时候请注意
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
这个地方一定要把这2个基本的地址,如果你需要更多的初始化选项参考下面的选项
不然启动服务的时候会出现
mysql The server quit without updating PID file
你启动mysql的时候就会出现这个问题,网上的解决办法很多,但是需要更具你自己的指定的data目录下的错误信息来判断
比如你上面你没指定
--basedir=/usr/local/mysql这个选项
localhost.localdomain.err 这个里面会提示
Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
因为默认的权限表不在/usr/local/mysql里面
还有一个问题就是/etc/my.ini也是配置文件确保整个的mysqld段里面
basedir=/usr/local/mysql/
datadir=/data/mysql/data
这2个是和/usr/local/mysql/my.ini里面都是一样
下面是错误日志的路径,如果以上问题还是解决不了。请查看日志
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
请参考下面的 这里注意下,很多文章没指出的,你下载mysql的源码包是由2中,一种是解压,直接 scripts/mysql_install_db的那个包,有200M左右,现在5.6的差不多有400M。一般你没看到cmake的编译的话,那就这种包 如果你的源码包只有20M-30M,你的包就需要cmake编译,你先的yum install cmake 这里演示的是cmake的 接下来是php 先解决几个编译php的编译选项的依赖库 libmcrypt mhash mcrypt libiconv 上面的源码包都有 cd /usr/local/src tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make && make install /sbin/ldconfig cd libltdl
./configure --enable-ltdl-install make && make install cd ../../ tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make && make install ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config cd ../ tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./configure make && make install cd ../ tar zxvf pcre-8.31.tar.gz cd pcre-8.31 ./configure –-prefix=/usr/local/pcre make make install cd ../ tar zxvf libiconv-1.13.1.tar.gz cd libiconv-1.13.1/ ./configure –-prefix=/usr/local/libiconv
这个地方做好指定,因为编译php的时候会搜索不到这个包
make && make install cd ../ tar zxvf ImageMagick.tar.gz cd ImageMagick-6.5.1-2/ ./configure make && make install cd ../ 接下来是重点,因为根据你架构的需求一下有很多不同,比如lamp就使用默认的工作模式即可,如果是lnmp的话就要使用fastcgi lanmp的也是要使用fastcgi模式 解释下为什么要使用lanmp处理php交给apache处理,静态文件交给nginx处理,因为nginx处理资源文件盒并发的能力更强,nginx作为反向代理有很多好处 比如集群轮换配置简单,并发能力强,目前并发最好的不是nginx而是lvs,但是就整体而言nginx好用程度和能力不逊色与LVS,如果你真的需要大并发的,其实lanmp的搭建方式 不行,以后再详细讨论 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-ttf --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-mcrypt 这个是默认工作模式,lanmp建议使用这个 ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-curl --enable-fpm --enable-soap --with-iconv=/usr/local/libiconv --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir=/usr/local/freetype --with-gd
如果不会安装gd或者libiconv请参看俺的其他文章
这是fpm模式 搭建lanmp必备 vi /etc/httpd/httpd.conf 增加2个东西就可以使用了 AddType application/x-httpd-php .php .php3 .htm .phtml .php4 AddType application/x-httpd-php-source .phps 支持php文件的支持 在增加支持DirectoryIndex index.php index.html 这个是全局的配置支持默认打开index.php 保存,重启apache service httpd stop service httpd start 测试 vi /usr/local/apache/htdocs/index.php <?php $con = mysql_connect('localhost','root',''); if($con){ echo "OK": }else{ echo "fuck"; } phpinfo(); ?> 显示了OK和phpinfo的信息 OK,php和mysql开启了 php是作为apache的模块执行,不需要作为服务启动 以下是配置虚拟机 vi /etc/httpd/httpd.conf 注释掉 # DocumentRoot "/usr/local/apache/htdocs/" 开启虚拟机主机 include "/etc/httpd/extra/httpd-vhost.conf" OK vi /etc/httpd/extra/httpd-vhosts.conf 默认是开启 mod_log_config模块,不放心就自己去 vi /etc/httpd/httpd.conf检查下 配置虚拟主机有2个默认配置 mkdir /www/{a.com,b.com} -pv mkdir /var/log/httpd/ <VirtualHost *:80> ServerName www.a.com DocumentRoot "/www/a.com" ErrorLog "/var/log/httpd/a.com-error_log" CustomLog "/var/log/httpd/a.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerName www.b.com DocumentRoot "/www/b.com" ErrorLog "/var/log/httpd/b.com-error_log" CustomLog "/var/log/httpd/b.com-access_log" common </VirtualHost> combined的日志文件更丰富 在自己的本地的hosts文件映射 192.168.0.206 www.a.com 192.168.0.206 www.b.com service httpd stop service httpd start 打开你会发现You don't have permission to access / on this server 因为从httpd2.4起,每个虚拟主机都需要主动配置目录才能访问 vi /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName www.a.com
DocumentRoot "/www/a.com"
<Directory "/www/b.com">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/a.com-error_log"
CustomLog "/var/log/httpd/a.com-access_log" common
</VirtualHost>
<VirtualHost *:80> ServerName www.b.com DocumentRoot "/www/b.com" <Directory "/www/b.com"> Options none AllowOverride none Require all granted </Directory> ErrorLog "/var/log/httpd/b.com-error_log" CustomLog "/var/log/httpd/b.com-access_log" common </VirtualHost> service httpd stop serveice httpd start OK.了 安装phpmyadmin cd /etc/local/src/ tar -zxvf phpMyAdmin-4.2.11-all-languages.tar.gz -C /www/a.com 就可以了,如果提示空密码不能登陆 mysqladmin -uroot password 'com' 如果提示要使用mysqli,就去再次编译一下php。或者扩展其他模块 下面是nginx groupadd nginx
useradd -r -g nginx nginx -s /sbin/nologin
id nginx tar -zxvf nginx-1.6.2 cd nginx-1.6.2 ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ make && make install vi /etc/init.d/nginxd #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql
chmod +x /etc/init.d/nginxd
chkconfig --add nginxd ##让入开机启动选项中
chkconfig nginxd on #让其开机自动启动
chkconfig --list #查看服务是不是加入
service nginxd start #立即启动nginx 服务
记住apache nginx默认端口都是80
yum -y install openssl-devel zlib-devel pcre-devel
yum groupinstall "Developement Tools" "Development Libraries" -yt
vi /etc/nginx/nginx.conf
server {
listen 81;
端口改成81
service nginxd start
OK
192.168.0.206:81
就可以看到欢迎页面
这个是php的fpm工作模式的配置
lnmp配置
cd /usr/local/src/php-5.6/
cp php.ini-production /usr/local/php/etc/php.ini
cp php.ini-production /etc/php.ini
这个是默认php.ini的路径
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
启用如下选项:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = run/php-fpm.pid
根据服务器配置修改
只需要把蓝色部分前面的注释去掉,修改完成,试着启动
/usr/local/php/sbin/php-fpm
启动后用netstat -tnlp 查看 如果有如图所示端口 测表示正常启动
如需要开机自动启动 则可以添加到/etc/rc.d/rc.local中
vim /etc/rc.d/rc.local
chkconfig --add fpm
chkconfig fpm on
chmod +x /etc/init.d/php-fpm
vi /etc/nginx/fastcgi_params
将里面内容替换为
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
vi /etc/nginx/nginx.conf
首先将
#user nobody;
改为user nginx;
之后找到
去掉#
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
server nginxd start
在nginx的根目录下
测试代码
vi index.php
<?php
phpinfo();
?>
192.168.0.206/index.php
可以看到
Server API的工作模式是fpm 这个是指lnmp架构已fpm工作模式工作
但是当nginx作为反向代理的时候 使用的配置文件还是apache的 显示的php的工作模式还是php已模块方式工作的
Server API Apache 2.0 Handler 因为php文件交给了httpd处理,显示的php信息还是apache的
这个时候请注意
你的php-fpm是不是还在运行
如果出现
iconv.c:1350: undefined reference to `libiconv'错误
tar -zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/libiconv
make
make install
--with-iconv=/usr/local/libiconv
php编译的时候指定路径就OK了
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-curl --enable-fpm --enable-soap --with-iconv=/usr/local/libiconv --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir=/usr/local/freetype --with-gd
这个fpm工作模式的编译选项
最后多说几句话,php5.4以后pdo本身不再是php的分支了已经合并
最后就是nginx反向代理apache,在nginx的配置文件里,吧apache的鉴定端口改为8080
定义server段
server里面可以定义location
静态文件处理交给nginx php处理交给apache
vi /etc/nginx/nginx.conf
location ~* \.(js|css|jpg|jpeg|gif|png)$ {
access_log off;
expires 1d;
}
location ~ ^(.+\.php)(.*)$ {
proxy_redirect off;
proxy_set_header HOST $host;
proxy_set_header SERVER_ADDR $server_addr;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header REMOTE_PORT $remote_port;
proxy_pass http://127.0.0.1:8080;
}
service nginxd stop
service nginxd start
查看phpinfo信息时,Server API Apache 2.0 Handler现在是这个模式运行证明,php交给apache处理了
让nginx反向代理apache时候,需要开启apche的虚拟机和nginx虚拟机,在nginx上也要配置比如我在apache监听的是81,那么反向代理的时候设置成http://127.0.0.1:81
首先配置nginx虚拟机
vi /etc/nginx/nginx.conf
user nginx nginx; #用户和用户组
worker_processes 2;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;epoll模型
worker_connections 65535;最大连接数
}
http {
include mime.types;
default_type application/octet-stream;
#主定义httpd
include /usr/local/nginx/vhost.conf;#引入读取的虚拟机配置文件也可以配置成×.conf也就是读取所有的配置文件,位置也可以自己选择
}
vi /usr/local/nginx/vhost.conf
fastcgi_param PATH_INFO $request_uri;
实现path_info支持
这个测试的时候apache监听是81请注意
server{
listen 80;
server_name www.b.com;
index index.php index.html;
root /www/b.com;
location ~ \.php$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
"/usr/local/nginx/vhost.conf" 37L, 941C written
[root@localhost ~]# vi /usr/local/nginx/vhost.conf
server{
listen 80;
server_name www.a.com;
root /www/a.com;
index index.php index.html;
location ~ \.php$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:81; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 1s;
}
location ~ .*\.(js|css)?$ {
expires 1s;
}
}
server{
listen 80;
server_name www.b.com;
index index.php index.html;
root /www/b.com;
location ~ \.php$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:81; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 1s;
}
location ~ .*\.(js|css)?$ {
expires 1s;
}
}
a如果你需要配置全局的nginx的请在
/etc/nginx/nginx.conf配置比如日志格式,gzip,各种代理配置
整个下面是apache的配置文件和上面配置的一样,只是
<VirtualHost *:81>
ServerName www.a.com
DocumentRoot "/www/a.com"
<Directory "/www/b.com">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/a.com-error_log"
CustomLog "/var/log/httpd/a.com-access_log" common
</VirtualHost>
<VirtualHost *:81>
ServerName www.b.com
DocumentRoot "/www/b.com"
<Directory "/www/b.com">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/b.com-error_log"
CustomLog "/var/log/httpd/b.com-access_log" common
</VirtualHost>