1、nginx 反向代理配置实例(前 nginx+,后 apache),z9c0e 凤凰总代 凤凰代理,nginx 反 向 代 理 配 置 实 例 ( 前 nginx+ 后,apache),我就拿我现在这个站的环境给大家看看,如果是一台普通 vps 或者是独立服务器,首,先我们要干的就是装环境和配置防火墙了,首先我们配置下防火墙吧,root51buyhostvim/etc/sysconfig/ipta,bles,:wq!保存退出,大家肯定会问 8889 端口是干嘛的,不用问了,等会看就知道了.,-AINPUT-mstate-stateNEW-mtcp-ptcp-dpo,rt22-jACCEPT,
2、-AINPUT-mstate-stateNEW-mtcp-ptcp-dpo,rt88-jACCEPT,-AINPUT-mstate-stateNEW-mtcp-ptcp-dpo,rt21-jACCEPT,-AINPUT-mstate-stateNEW-mtcp-ptcp-dpo,rt80-jACCEPT,还有一件事需要做的就是 selinux,可能大家会觉得我啰嗦.错.这些我主要是对新手来讲的,如果你是老手你跳到最下面看的我配置文件就行.,root51buyhostvim/etc/sysconfig/seli,nux 打开 selinux 配置文件,在里面把所有的都注释掉新增一个,SELINU
3、X=disabled,:wq!保存退出,重启服务器root51buyhostreboot,等服务器重启完毕之后我们就开始安装环境了注意,我给大家介绍的全部是 yum 源安装.喜欢编译的安装的自己在编译安装之前需安装编译需要的依赖包以及 g 等等那些工具.在此我提醒大家.很多人的服务器环境是最小化安装版,最小,化安装版是不适合编译安装环境的如果是的话请手动用 yum 安装所需要的编译环境不说了咱们开始,首先安装 nginx 吧这种方法是教大家安装,nginx 最新版本的,root51buyhostvim/etc/yum.repos.d/Ce,ntOS-Base.repo,在最后一行加上如下内容,
4、nginx,name=nginxrepo,baseurl=/packages/centos/$releasever/$b,asearch/,gpgcheck=0,enabled=1,:wq!保存退出,下面开始安装 nginx 了,root51buyhostyuminstallnginx,提示按 y,安装 mysql,root51buyhostyuminstallmysql-server,提示按 y,安装 php,root51buyhostyuminstallphp-y,提示按 y,安装 php 的扩展插件,root51buyhostyuminstallphp-mysqlphp-gdlibjpe
5、g*php-ldapphp-odbcphp-pearphp-xmlphp-xmlrpcphp-mbstringphp-mcryptphp-bcmathphp-mhashlibmcryptlibmcrypt-devel,好了.以上就是 lnmp 环境的完整安装了.,接下来我们需要把/etc/nginx/目录下面的,nginx.conf 这个里面的内容全部修改,最好是先把默认的 nginx.conf 这个配置文件,备份下吧.,root51buyhostcd/etc/nginx,备份重新命名为 nginx.confbak,接下来新建立一个 nginx.conf 配置文件,输入一下内容:,userng
6、inxnginx;,worker_processes1;,error_log/var/log/nginx/error.logwarn;,pid/var/run/nginx.pid;,events,worker_connections1024;,http,include/etc/nginx/mime.types;,default_typeapplication/octet-stream;,server_tokensoff;,server_names_hash_bucket_size128;,client_header_buffer_size32k;,large_client_header_buf
7、fers432k;,client_max_body_size50m;,sendfileon;,tcp_nopushon;,keepalive_timeout60;,tcp_nodelayon;,fastcgi_connect_timeout300;,fastcgi_send_timeout300;,fastcgi_read_timeout300;,fastcgi_buffer_size64k;,fastcgi_buffers464k;,fastcgi_busy_buffers_size128k;,fastcgi_temp_file_write_size256k;,gzipon;,gzip_mi
8、n_length1k;,gzip_buffers416k;,gzip_http_version1.0;,gzip_p_level2;,gzip_typestext/plainapplication/x-javas,cripttext/cssapplication/xml;,gzip_varyon;,proxy_set_headerHost$host;,proxy_set_headerX-Real-IP$remote_addr;,proxy_set_headerX-Forwarded-For$proxy_a,dd_x_forwarded_for;,log_formatmain$remote_ad
9、dr-$remote_,user$time_local“$request“,$status$body_bytes_sent“$http_refer,er“,“$http_user_agent“$http_x_forwarde,d_for“,server,listen80;,server_name51buyhost;,indexindex.htmlindex.htmindex.php;,root/data/51buyhost;,location/,try_files$uriapache;,locationapache,internal;,proxy_pass0.0.1:88;,includepr
10、oxy.conf;,location.*.(php|php5)?$,proxy_pass0.0.1:88;,includeproxy.conf;,location/status,stub_statuson;,aess_logoff;,location.*.(gif|jpg|jpeg|png|bmp|swf)$,aess_logoff;,expires30d;,location.*.(js|css)?$,aess_logoff;,expires12h;,aess_log/data/log/51buyhost/aess.log;,include/etc/nginx/conf.d/*.conf;,以
11、上是我服务器的主配置文件了,只真对这个站的.虚拟主机配置文件我就不,亮出来了.,以上就是 nginx 的整个配置文件了.还有一个,虚拟主机在里面,下面我亮出我的 apache 配置文件,apache 配置文件比较多我只告诉大家我修改,了哪些地方而已,root51buyhostvim/etc/httpd/conf/htt,pd.conf,在大概 136 行的样子增加以下内容,把默认的 80 端口注释,Listen127.0.0.1:88,还有在最下面增加以下内容,Include/etc/httpd/conf/51buyhost.conf,我给大家最好都是默认的配置吧,因为个人有,个人的配置访问,
12、我测试的时候只在 apache 配置文件里加了以上内容,接下来就设置 51buyhost.conf 的内容,上面带了 dz 伪静态的规则,VirtualHost*:88,DocumentRoot“/data/51buyhost“,ServerName,ServerAlias51buyhost,Directory“/data/51buyhost“,allowfromall,Options+Indexes,/Directory,IfModulemod_rewrite.c,RewriteEngineOn,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/to
13、pic-(.+).html$1/por,tal.php?mod=topic%1,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/article-(0-9+)-(0-9+).html$1/portal.php?mod=viewaid=$2&,amp;page=$3%1,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/forum-(w+)-(0-9+).html$1/forum.php?mod=forumdisplayfid=$2,%1,RewriteCond%QUERY_STRING(.*)$,Rewrite
14、Rule(.*)/thread-(0-9+)-(0-9+)-(0-9+).html$1/forum.php?mod=viewthrea,d%1,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/group-(0-9+)-(0-9+,).html$1/forum.php?mod=group%1,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/space-(username|uid)-(,.+).html$1/home.php?mod=space%1,RewriteCond%QUERY_STRING(.*)$,R
15、ewriteRule(.*)/blog-(0-9+)-(0-9+),.html$1/home.php?mod=space%1,RewriteCond%QUERY_STRING(.*)$,RewriteRule(.*)/(a-z+a-z0-9_*)-(a,-z0-9_-+).html$1/plugin.php?id=$2:$3%1,RewriteCond%http_host51buyhostNC,RewriteRule(.*)$51buyhostL,R=301,/IfModule,IfModulemod_mem_cache.c,CacheEnablemem/,MCacheMaxObjectCou
16、nt20000,MCacheMaxObjectSize1048576,MCacheMaxStreamingBuffer65536,MCacheMinObjectSize10,MCacheRemovalAlgorithmGDSF,MCacheSize4096,CacheMaxExpire864000,CacheDefaultExpire86400,CacheDisable/php,/IfModule,/Directory,ExpiresActiveon,ExpiresBytypetext/css“aessplus3days,ExpiresByTypeapplication/x-javascript“a,essplus3days“,ExpiresByTypeimage/jpeg“aessplus3days“,Expiresbytypeimage/gif“aessplus3days“,Expiresbytypeimage/png“aessplus3days“,/Directory,/VirtualHost,