技术文档

关于Nginx与Apache共存的解决方法

Nginx+Apache结构,其实就是Nginx做前端,Apache做后端,充分发挥他们各自的优势之处。Nginx对于高并发性能出众,Proxy功能强效率高,占用系统资源少,而Apache在高并发时对队列的处理比FastCGI(Nginx需要通过fastcgi等方式运行php)更好,并且在处理动态php页面时,mod_php也比php-cgi更稳定更高效。

关于Nginx与Apache共存的解决方法

由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 www. ;

 

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 www.

ServerAlias www.

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 www.;

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;

}

 

}


SSL证书是HTTPS加密协议必备条件,是网络安全传输的加密通道。而(GDCA)的SSL证书是国际WEBTRUST认证认可的国际数字证书,是升级HTTPS的最佳选择。并且(GDCA)是国际知名品牌:GlobalSign、Symantec、GeoTrust SSL证书国内金牌代理商。因此拥有多种国际证书,满足各种用户对SSL的各种要求,广大用户可根据自身的需求向申请合适的SSL证书,的专业团队将会为您提供最佳的HTTPS解决方案。

©2020-2024   万云SSL证书  (www.sslssl.com.cn)  万云科技   豫ICP备2020034358号-10