我正在尝试使用nginx工作的docker容器作为其他docker容器的反向代理,并且我继续在除了基本位置'/'之外的其他位置上获得"Bad Gateway".
我有以下服务器块:
server {
listen 80;
location / {
proxy_pass "http://game2048:8080";
}
location /game {
proxy_pass "http://game:9999";
}
}
Run Code Online (Sandbox Code Playgroud)
它适用http://localhost但不适用于http://localhost/game浏览器中的"Bad Gateway"和nginx容器上的"Bad Gateway":
[error] 7#7: *6 connect() failed (111: Connection refused)
while connecting to upstream, client: 172.17.0.1, server: ,
request: "GET /game HTTP/1.1", upstream: "http://172.17.0.4:9999/game",
host: "localhost"
Run Code Online (Sandbox Code Playgroud)
我使用官方的nginx docker镜像并在其上放置我自己的配置.您可以在此处测试并查看所有详细信息:https: //github.com/jollege/ngprox1
任何想法出了什么问题?
注意:我在docker主机上设置了本地主机名条目以匹配这些名称:
127.0.1.1 game2048
127.0.1.1 game
Run Code Online (Sandbox Code Playgroud) 当我尝试在数字海洋中托管的项目中上传大小约为 600MB 的大 csv 文件时,它尝试上传但显示 502 Bad Gateway Error (Nginx)。
该应用程序是一个数据转换应用程序。
这在本地工作时效果很好。
sudo tail -30 /var/log/nginx/error.log
Run Code Online (Sandbox Code Playgroud)
节目
[error] 132235#132235: *239 upstream prematurely closed connection while reading response header from upstream, client: client's ip , server: ip, request: "POST /submit/ HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/submit/", host: "ip", referrer: "http://ip/"
sudo nano /etc/nginx/sites-available/myproject
Run Code Online (Sandbox Code Playgroud)
节目
server {
listen 80;
server_name ip;
client_max_body_size 999M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /root/static/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock; …Run Code Online (Sandbox Code Playgroud) 我有以下nodejs Web套接字服务器
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(8000);
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
console.log("Listening on 8000");
Run Code Online (Sandbox Code Playgroud)
尝试连接时使用 wscat
wscat -c ws://localhost:8000/
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
error: Error: socket hang up
Run Code Online (Sandbox Code Playgroud)
它在浏览器中使用以下javascript工作得很好
var socket = io.connect('http://localhost:8000');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
Run Code Online (Sandbox Code Playgroud)
感谢帮助!