Nginx使用NodeJS和Apache

3
我有两台服务器:A运行Nodejs Web应用程序,B运行PHP Web应用程序。我想配置Nginx,使得当我输入http://www.example.com时,它路由到Nodejs Web应用程序;然后如果我输入http://www.example.com/otherinternalpage,它会路由到PHP Web应用程序。
服务器A和B都在同一个内部网络中,我已经在服务器A上安装了Nginx。
感谢任何形式的帮助。 谢谢。
1个回答

1

可以实现,但我建议使用不同的子域和一个ngnix配置文件来管理每个应用程序,就像我为自己的项目所做的那样:

  • www.leave-management-system.org
  • demo.leave-management-system.org
  • influxdb.leave-management-system.org
  • 等等。

优点是您可以禁用一个应用程序而不影响其他应用程序,并且当它以不同的文件形式出现时,配置更容易维护。

无论如何,您需要(按链接):

但是,如果您不想使用子域,而是在同一域上使用两个不同的文件夹,则组合配置可能如下所示:

server { 
    listen 80 default;
    server_name www.example.com;
    ...

    location /otherinternalpage/  {
        try_files $uri $uri/ /index.php?/$request_uri;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        #This is a Linux socket config
        #fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        #Alternatively, you can configure nginx/PHP with a backend
        fastcgi_pass 127.0.0.1:{YOUR_PORT};
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME
            $document_root$fastcgi_script_name;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
    }

    location / {
        proxy_pass http://localhost:{YOUR_PORT};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

非常感谢您的回答,php服务器托管在同一私有网络中的另一个位置,因此我得到了一个获取文件的URL。它名为organization.example.com,因此来自用户的请求 http://www.example.com/otherinternalpage 应该重定向到 organization.example.com,当响应返回时,我仍希望用户的URL具有http://www.example.com/otherinternalpage/PAGE_REQUESTED。是否可能拥有这种配置?再次感谢! - gaurrus
我编辑了我的回答。需要做一些更改以适应您的需求。您没有解释您的PHP应用程序的工作方式,因此您可能需要更改位置部分,请参阅http://nginx.com/resources/admin-guide/reverse-proxy/。 - Benjamin BALET

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接