我有两个服务器:A运行Nodejs web应用程序,B运行PHP web应用程序。我想以这样一种方式配置Nginx,即当我键入http://www.example.com它路由到nodejs web应用程序那么如果我键入http://www.example.com/otherinternalpage它路由到PHP web应用程序。
服务器A和B都在同一个内联网中,我在服务器A中安装了Nginx。
我请求任何帮助。感谢
这是可能的,但我建议为每个应用程序使用不同的子域和ngnix配置文件,就像我为自己的项目所做的那样:
- www.leave-management-system.org
- demo.leave-management-system.org
- influxdb.leave-management-system.org
- 等等
其优点是,您可以在不影响其他应用程序的情况下禁用一个应用程序,并且配置在不同文件中时更易于维护。
无论如何,你需要(按照链接):
- 将nginx配置为反向代理
- 永远运行Nodejs
- 使用PHP FPM将PHP作为FastCGI进程运行
然而,如果你不想使用子域,而是在同一个域上使用两个不同的文件夹,那么组合配置可能看起来像这样:
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;
}
}