189 8069 5689

nginx与apache反向代理

nginx与apache一起做反向代理,各自的优点就不细说了,反正一个处理并发及静态的牛差差,一个处理动态的牛差差。

成都创新互联公司专注于西峡网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供西峡营销型网站建设,西峡网站制作、西峡网页设计、西峡网站官网定制、成都微信小程序服务,打造西峡网络公司原创品牌,更为您提供西峡网站排名全网营销落地服务。

想看apache如何运行安装,可以查看我的另一篇centOS7 LAMP安装及注意要点。

1、apache相关配置文件更改端口号

主配置文件:

vi/etc/httpd/conf/httpd.conf Listen81

虚拟主机配置文件:

vi/etc/httpd/conf.d/lock.com.conf DirectoryIndexindex.php ServerAdmin2871903572@qq.com DocumentRoot/www/lockcom ServerNamelock.com ServerAliaslock.com OptionsIndexesFollowSymLinks AllowOverrideNone Requireallgranted

2、nginx安装

用yum来安装吧

yumnginxinstall /bin/systemctlstartnginx.service systemctlstatusnginx.service

应该是nginx欢迎页面

3、更改nginx相关配置文件

nginx.conf主配置文件:

主要是proxy_pass做反向代理

如果你在apache虚拟主机用了固定IP地址话,proxy_pass应该是一样的IP地址,如果没有设置,正常用127.0.0.1就可以。

同时建立nginx的虚拟主机配置目录,并在主配置文件下包含:include /etc/nginx/vhost/*.conf;

mkdir/etc/nginx/vhost touch/etc/nginx/vhost/lock.com.conf

下面nginx主配置文件:

nginx.conf

#Formoreinformationonconfiguration,see: #*OfficialEnglishDocumentation:http://nginx.org/en/docs/ #*OfficialRussianDocumentation:http://nginx.org/ru/docs/ usernginx; worker_processesauto; error_log/var/log/nginx/error.log; pid/run/nginx.pid; events{ worker_connections1024; } http{ log_formatmain\'$remote_addr-$remote_user[$time_local]"$request"\' \'$status$body_bytes_sent"$http_referer"\' \'"$http_user_agent""$http_x_forwarded_for"\'; access_log/var/log/nginx/access.logmain; sendfileon; tcp_nopushon; tcp_nodelayon; keepalive_timeout65; types_hash_max_size2048; include/etc/nginx/mime.types; default_typeapplication/octet-stream; #Loadmodularconfigurationfilesfromthe/etc/nginx/conf.ddirectory. #Seehttp://nginx.org/en/docs/ngx_core_module.html#include #formoreinformation. include/etc/nginx/conf.d/*.conf; server{ #listen80default_server; #listen[::]:80default_server; listen80; server_name_; #root/usr/share/nginx/html; #Loadconfigurationfilesforthedefaultserverblock. #include/etc/nginx/default.d/*.conf; location/{ try_files$uri@apache; } location@apache{ internal; proxy_passhttp://192.168.136.128:81; } location~.*.(php|php5)?${ proxy_passhttp://192.168.136.128:81; } location~.*.(gif|jpg|jpeg|png|bmp|swf|flv|ico)${ expires30d; } location~.*.(js|css)?${ expires7d; } error_page404/404.html; location=/40x.html{ } error_page500502503504/50x.html; location=/50x.html{ } } include/etc/nginx/vhost/*.conf; }

虚拟主机下的配置vhost/lock.com.conf

vi/etc/nginx/vhost/lock.com.conf server{ listen80; server_namelock.com; access_log/www/wwwlogs/lock.com_nginx.logcombined; indexindex.htmlindex.htmindex.jspindex.php; root/www/lockcom; #error_page404/404.html; if($query_string~*".*[;\'<>].*"){ return404; } if($http_user_agent~ApacheBench|WebBench|Jmeter|must-revalidate|Havij){ return503; } location~.*.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)${ valid_referersnoneblockednahehuo.com*.nahehuo.com; if($invalid_referer){ #rewrite^/http://www.lock.com/403.html; return403; } } limit_rate500k; location/{ try_files$uri@apache; } location@apache{ internal; proxy_passhttp://192.168.136.128:81; } location~.*.(php|php5)?${ proxy_passhttp://192.168.136.128:81; } location~.*.(gif|jpg|jpeg|png|bmp|swf|flv|ico)${ expires30d; } location~.*.(js|css)?${ expires7d; } }


标题名称:nginx与apache反向代理
文章分享:http://jkwzsj.com/article/cjhojd.html

其他资讯