nginx+apache前后台搭配使用

nginx apache都是web服务器

但是nginx更轻型对静态处理强大,而且nginx也是反向代理服务器,可以作转发
apache比较重型,非常稳定,处理动态WEB程序非常好,但是对静态处理就比较一般
 
比如有一种情况比如我们一台服务器A只有内网,没有外网,一台服务器B有外网,
如果我们想要访问A上的WEB程序,那么怎么办,我们可以通过B来实现,B上装nginx转发A上的WEB程序
这样可以实现
用nginx转发还有一个好处,就是静态不通过apache,动态转发给apache处理直接转发处理的结果
这样可以实现分布式
那么说说我的配置
系统是unbuntu 11.10
apache 2.2.22  nginx 1.8.1
apache 81端口 nginx 80端口
我的apache和nginx在一台服务器上
 
apache使用81端口就不说了,
 
nginx配置文件在/etc/nginx/
其实有两种办法
第一种修改nginx.conf文件
第二种  修改sites-enable/default文件
我一般修改default文件
我的default文件
listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6
 
root /var/www;
index index.html index.htm index.php;
 
# Make site accessible from http://localhost/
server_name localhost;
 
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;#默认配置
}
 
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
        location ~* .*\.(gif|jpg|jpeg|png|bmp|ico|css|js|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
            expires 2d;#缓存2天
        }
location ~ .*\.(php?|cgi|pl|py)$ {
            proxy_pass http://127.0.0.1:81;  #这个就是转发地址
        }
重启nginx和apache就可以
 
注意防火墙要记得开通80端口,如果外围访问的话
 
iptables放行80端口localhost@root#  iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT 
 
 
 
 
 
posted @ 2016-11-18 11:35  菜的掉渣  阅读(496)  评论(0编辑  收藏  举报