首页域名资讯 正文

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

2024-10-16 2 0条评论

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

ServerAlias  www.trustauth.cn trustauth.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    trustauth.cn www.trustauth.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;

}

 

}


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

文章版权及转载声明

本文作者:亿网 网址:https://edns.com/ask/post/151288.html 发布于 2024-10-16
文章转载或复制请以超链接形式并注明出处。