Linux服务器下Nginx与Apache共存如何实现

同一个端口是不能同时有两个程序监听的。所以换个思路解决同一台服务器下某些网站运行在nginx下,某些网站运行在apache下共存。

解决思路:

将nginx作为代理服务器和web服务器使用,nginx监听80端口,apache监听除80以外的端口,我这暂时使用8080端口。

Linux服务器下Nginx与Apache共存如何实现

解决方案:

在linux 一经搭建好环境 先后安装了nginx 和apache 由于 默认端口都是:80

一般客户请求的服务器端口默认为80 所以nginx作为静态页端口设置:80;apache设置端口为:8080(在httpd.conf 文件中修改listen:8080)

apache下的网站:

在nginx.conf中 添加

  1. server {   listen  80;   server_name www.one.ityangs.cn one.ityangs.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中 添加

  1. servername www.one.ityangs.cnserveralias www.one.ityangs.cn one.ityangs.cndocumentroot /www/onedirectoryindex index.php index.htmloptions +includes +followsymlinks -indexesallowoverride allorder deny,allowallow from all

登录后复制

nginx下的网站:

在nginx.conf中 添加

  1.  server {  listen  80;  server_name two.ityangs.cn www.two.ityangs.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;  }}

登录后复制

以上就是Linux服务器下Nginx与Apache共存如何实现的详细内容,更多请关注【创想鸟】其它相关文章!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
编程技术

怎么实现Nginx高可用

2025-4-2 5:31:27

编程技术

Nginx做NodeJS应用负载均衡配置的方法

2025-4-2 5:31:36

0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
私信列表
搜索