我正在尝试安装一个带有NGINX和NuxtJS的Docker容器,它将托管在AWS中。我以后可能会为它设置DNS,但现在我还不知道URL。是否要告诉NGINX/socket.io使用正在运行容器的机器的地址?
我一直使用'localhost‘作为占位符值,在我的本地机器上开发时很好。但是当托管在EBS上时,应用程序仍然试图连接到套接字端口上的我的机器。
当前设置
nginx配置:
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://nuxt:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}socket.io (这是来自一个模块,但您可以看到url设置为localhost)
io: {
sockets: [{
default: true,
name: 'mainSocket',
url: 'http://localhost:3000'
}],
},码头组成文件
version: "3.8"
services:
nuxt:
build: ./app
restart: always
ports:
- "3000:3000"
command:
"npm run start"
nginx:
image: nginx:1.19
ports:
- "80:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- nuxt有什么建议吗?
发布于 2021-10-03 00:39:58
根据user253751的注释,window.location包含有关应用程序的URL的数据。在我使用的模块中,这个值很容易访问。情况可能并不总是如此。
https://stackoverflow.com/questions/69407539
复制相似问题