• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    Linux服务器下Nginx与Apache共存的实现方法分析

    本文实例讲述了Linux服务器下Nginx与Apache共存的实现方法。分享给大家供大家参考,具体如下:

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

    解决思路:

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

    解决方案:

    Apache下的网站:

    在nginx.conf中 添加

    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中 添加

    <virtualhost *:8080>
    ServerName www.one.ityangs.cn
    ServerAlias www.one.ityangs.cn one.ityangs.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 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服务器维护有所帮助。

    上一篇:CentOS使用本地yum源搭建LAMP环境图文教程
    下一篇:部署前后端分离式nginx配置的完整步骤
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    Linux服务器下Nginx与Apache共存的实现方法分析 Linux,服务器,下,Nginx,与,