Jump to content
新域网络技术论坛

Apache与Nginx共存相应设置


Jamers
 Share

Recommended Posts

Nginx由于对于静态页面处理效率高于Apache,但是对于动态页面处理不如Apache,所以可以让Nginx处理静态的页面,对于动态页面反向代理给Apache处理。

 

1. 正常安装Apache,保证页面可以访问。修改httpd.conf,将

Listen 80
#修改为,使Apache只监听本地端口
Listen 127.0.0.1:80

2. 正常安装Nginx,测试可以访问后,修改配置文件nginx.conf

#将location /段修改成以下内容,注释掉的那行是原来nginx默认的,我们改成与apache同目录
        location / {
            #root   /usr/local/www/nginx;
            root   /usr/local/www/apache24/data;
            index  index.php index.html index.htm;
        }

#以下内容默认是不存在的,直接添上或者修改,PHP文件处理规则
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location ~ /\.ht {
            deny  all;
        }

这样静态页面就由nginx处理了,动态交给apache处理了。

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...