我知道可以使用Nginx在一台服务器上运行多个node.js . 我已经安装了Nginx并在Ubuntu服务器上运行 . 我有两个节点js应用程序:
127.0.0.1:3001 and
127.0.0.1:3002
. 我想用不同的URL访问不同的应用程序 . 例如,如果我想访问
127.0.0.1:3001
,我会使用url:
http://121.42.20.100/
. 如果想要访问
127.0.0.1:3002
的应用程序,我会使用url:
http://121.42.20.100/admin
文件夹站点上的默认文件 - 可用如下:
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from ` http://localhost/`
server_name 0.0.0.0;
location / {
proxy_pass ` http://127.0.0.1:3001`;
}
location /admin/ {
proxy_pass ` http://127.0.0.1:3002`;
}
}
当我访问url时
http://121.42.29.100/
,它可以从
127.0.0.1:3001
获得响应 . 但是,当我像
http://121.42.29.100/admin
那样访问url时,它显示错误"Cannot GET /admin/"不起作用 . 如何配置nginx才能使其正常工作?