[root@localhost nginx]# vi conf/nginx.conf
location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# 3fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
}
8:20
[root@localhost local]# rpm -e httpd-tools-2.2.15-29.el6.centos.x86_64 [root@localhost local]# rpm -e httpd-2.2.15-29.el6.centos.x86_64 --nodeps
[root@localhost local]# rpm -e httpd-2.2.15-29.el6.centos.x86_64 --nodeps
[root@localhost local]# rpm -e jakarta-commons-httpclient-3.1-0.9.el6_5.x86_64 --nodeps
[root@localhost soft]# wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.18.tar.gz
[root@localhost test]# tar -jxf apr-1.5.1.tar.bz2
./configure --prefix=/usr/local/apr
# make && make install
[root@localhost test]# tar -zxf apr-util-1.5.4.tar.gz
[root@localhost test]# cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
[root@localhost soft]# tar -jxf httpd-2.4.10.tar.bz2
./configure --prefix=/usr/local/httpd \
--sysconfdir=/etc/httpd --enable-so --enable-ssl \
--enable-cgi --enable-rewrite --with-zlib --with-pcre \
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \
--enable-modules=most
配置文件路径为:/etc/httpd/httpd.conf
添加进环境变量:
# echo 'export PATH=$PATH:/usr/local/httpd/bin' > \
/etc/profile.d/httpd.sh
chmod +x /etc/profile.d/httpd.sh
[root@localhost httpd]# vim /etc/httpd/httpd.conf
listenen 8080
ServerName localhost:8080
[root@localhost bin]# killall -9 httpd
[root@localhost bin]# netstat -tulnp | grep '8080'
[root@localhost bin]# ./apachectl start
[root@localhost bin]# killall -9 httpd###可能有多个htppd服务
[root@localhost bin]# ./apachectl start
http://192.168.88.206:8080/
It works!
[root@localhost extra]# cd /etc/httpd/extra
[root@localhost extra]# vi httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/nginx/html"
ServerName 192.168.88.206
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
[root@localhost extra]# vim /etc/httpd/httpd.conf
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf
[root@localhost bin]# ./apachectl restart
[root@localhost extra]# vim /etc/httpd/httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
<Directory "/usr/local/httpd/htdocs">
AllowOverride all#######
</Directory>
[root@localhost bin]# ./apachectl restart
[root@localhost ecshop]# cd /usr/local/nginx/html/ecshop
[root@localhost ecshop]# vi index.html
[root@localhost nginx]# vi conf/nginx.conf
location ~ \.php$ {
proxy_pass http://192.168.88.206:8080
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# 3fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
./configure --prefix=/usr/local/fastphp \
--with-mysql=mysqlnd \
--enable-mysqlnd \
--with-gd \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-apxs2=/usr/local/httpd/bin/apxs
用nginx做反向代理和负载均衡非常简单,
支持两个用法 1个proxy, 1个upstream,分别用来做反向代理,和负载均衡
以反向代理为例, nginx不自己处理php的相关请求,而是把php的相关请求转发给apache来处理.
----这不就是传说的”动静分离”,动静分离不是一个严谨的说法,叫反向代理比较规范.
反向代理后端如果有多台服务器,自然可形成负载均衡,
但proxy_pass如何指向多台服务器?
把多台服务器用 upstream指定绑定在一起并起个组名,
然后proxy_pass指向该组
默认的均衡的算法很简单,就是针对后端服务器的顺序,逐个请求.
也有其他负载均衡算法,如一致性哈希,需要安装第3方模块.
反向代理导致了后端服务器的IP,为前端服务器的IP,而不是客户真正的IP,怎么办?
转载于:https://my.oschina.net/goudingcheng/blog/631743