自知则知之

2019-01-10  本文已影响0人  竝離

转载:https://blog.csdn.net/ITYang_/article/details/53907937

linux服务器下nginx与apache共存

思路:

将nginx作为代理服务器和web服务器使用,nginx监听80端口,apache监听除80端口以外的端口,这里使用8080端口.
过程

方案:

1.在linux一经搭建好环境先后安装了nginx和apache,默认端口号都是:80
2.一般客户请求的服务器端口默认为80所以nginx作为静态页端口设置:80;Apache设置为:8080(在httpd.conf文件中修改listen:8080)
3.配置nginx转发请求

nginx配置添加:

server {
            listen          80;
            server_name www.one.guapi.com  one.guapi.com;
           
       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.guapi.com
ServerAlias         www.one.guapi.com one.guapi.com
DocumentRoot    /www/one
DirectoryIndex    index.php   index.html
<Directory /www/guapi>
Options +Includes +FollowSymLink -Indexes
AllowOverride     All
Order                Deny,Allow
Allow         from All
</Directory>
</virtualhost>

nginx下网站配置添加:

server { 
          listen              80;
          server_name     two.guapi.com www.two.guapi.com;
          root                /www/two;
          location           /{
                  index index.html index.php;
                  if (!-e $request_filename) {
                      rewrite ^(.*)$  /index.php?s=$1     last;
                      break;
                  }
                  
           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;
  }
  ```
上一篇 下一篇

猜你喜欢

热点阅读