Nginx+Apache结构,其实就是Nginx做前端,Apache做后端,充分发挥他们各自的优势之处。Nginx对于高并发性能出众,Proxy功能强效率高,占用系统资源少,而Apache在高并发时对队列的处理比FastCGI(Nginx需要通过fastcgi等方式运行php)更好,并且在处理动态php页面时,mod_php也比php-cgi更稳定更高效。
由Nginx来接收客户端的请求,如果是动态页面请求,就交给Apache处理,然后经由Nginx再返回给客户端,其余的请求,则由Nginx自己处理,然后把结果返回给客户端。也可以让Nginx只做Proxy功能,所有的请求都交给Apache,Tomcat等处理。
下面研究解决同一台服务器下某些网站运行在Nginx的下,某些网站运行在Apache的下共存。
将nginx的作为代理服务器和网络服务器使用,nginx的监听80端口,Apache的监听除80以外的端口,这里暂时使用8080端口。

在Linux一经搭建好环境先后安装了Nginx和Apache由于默认端口都是:80
一般客户请求的服务器端口默认为80所以Nginx作为静态页端口设置:80; Apache设置端口为:8080(在httpd.conf文件中修改Listen:8080)
阿帕奇下的网站:
在nginx.conf中添加
server {
listen 80;
server_name http://www.example.cn example.cn;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
在httpd.conf中添加
<virtualhost *:8080> ServerName http://www.example.cn ServerAlias http://www.example.cn http://example.cn DocumentRoot /www/one DirectoryIndex index.php index.html <Directory /www/one> Options +Includes +FollowSymLinks -Indexes AllowOverride All Order Deny,Allow Allow from All </Directory> </virtualhost> Nginx的下的网站: 在nginx.conf中添加 server { listen 80; server_name http://example.cn www.example.cn; root /www/two; location /{ index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } error_page 404 /var/www/html/404.html; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }

