lnmpa前端nginx后端apache配置案例

本文就是实现Nginx作为前端,apache作为后端。当用户访问的是80端口的nginx,然后nginx将静态内容留给自己,其余的转发给非80端口的apache,apache处理完毕后再回传给nginx。

1.修改(或者添加)nginx配置(vhost),本案例在nginx/conf/vhosts里面创建文件test.conf

#cat /usr/local/nginx/conf/vhosts/test.conf
server {
    listen       80;
    server_name  项目域名;
    root /home/wwwroot/test;
    index index.html index.php ;
    error_page 404 @proxy;
    include proxy-pass-php.conf;
}

  以上配置中的proxy-pass-php.conf,在nginx的conf文件夹中,proxy-pass-php.conf内容如下:

        location /
        {
            try_files $uri @apache;
        }

        location @apache
        {
            internal;
            proxy_pass http://127.0.0.1:88;
            include proxy.conf;
        }

        location ~ [^/]\.php(/|$)
        {

            proxy_pass http://127.0.0.1:88;
            include proxy.conf;
	}
	# nginx找不到文件时,转发请求给后端Apache
    	location @proxy {
        	proxy_set_header Host $http_host;
        	proxy_set_header X-Real-IP $remote_addr;
        	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_pass http://127.0.0.1:88;
    	}

  

2.nginx配置完毕,接下来就要配置apache了,首先确定apache的端口与上面配置的一致(上面配置了88端口是apache的),找到apache/conf/httpd.conf这个文件,修改监听端口:

Listen 127.0.0.1:88

3.配置apache的vhost,该目录一般在apache/conf/vhost,本案例在apache/conf/vhost创建test.conf,内容如下:

<VirtualHost *:88>
ServerAdmin admin@email.com
#php_admin_value open_basedir "/ home / wwwroot:/ tmp /:/ var / tmp /:/ proc /"
DocumentRoot  /home/wwwroot/test
ServerName  项目域名
   <Directory /home/wwwroot/test/>
       allow from all
   </Directory>
</Virtualhost>

  

4.重启ngnix和apache

service ngnix restar
service httpd restar

  

 

posted @ 2019-04-05 21:09  全帅  阅读(1358)  评论(0编辑  收藏  举报