怎么了:
我使用以下nginx.conf文件进行负载平衡。 Web应用程序已在nginx 8080端口上启动并运行,并且能够访问登录页面。但是,当从登陆页面移动到“注册”页面时,它会抛出错误。
预期结果:
nginx负载均衡器应该将负载重定向到位置指令中提到的页面。但那并没有发生。
nginx文件:
events {
}
http {
upstream 3.121.253.126 {
server 3.121.253.126:8080;
server 3.121.253.126:8080;
server 3.121.253.126:8080;
}
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
server {
listen 8080;
server_name 3.121.253.126;
root /etc/nginx/html;
index index.html;
location /signup {
root /etc/nginx/html;
index add-user.html;
# proxy_pass http://localhost:8080/signup;
# proxy_set_header Host $host;
# rewrite ^/welcome(.*)$ $1 break;
}
}
}
这是错误日志:
2019/02/21 09:07:42 [错误] 6#6:* 510 recv()失败(104:对等连接重置)从上游读取响应头,客户端:127.0.0.1,服务器:3.121.253.126,请求:“GET /注册HTTP / 1.0”,上游:“http://127.0.0.1:8080/signup”,主持人:“localhost:8080”,推荐人:“http://3.121.253.126:8080/”2019/02/21 09:07:42 [警告] 6#6:* 510上游服务器在从上游读取响应头时暂时禁用,客户端:127.0.0.1,服务器:3.121.253.126,请求:“GET / signup HTTP / 1.0”,上游:“http://127.0.0.1:8080/signup”,主机:“localhost:8080”,引用:“ http://3.121.253.126:8080/“2019/02/21 09:13:10 [错误] 6#6:* 1打开()”/ etc / nginx / html / signup“失败(2:没有这样的文件或目录),客户端:157.33.175.127 ,服务器:3.121.253.126,请求:“GET / signup HTTP / 1.1”,主持人:“3.121.253.126:8080”,推荐人:“http://3.121.253.126:8080/”2019/02/21 09:15:57 [错误] 6#6: * 3 open()“/ etc / nginx / html / signup”失败(2:没有这样的文件或目录),客户端:157.33.175.127,服务器:3.121.253.126,请求:“GET / signup HTTP / 1.1”,主机:“3.121.253.126:8080”,推荐人:“q azxswpoi”
根据日志,它期待注册HTML文件。但是,我指示它使用add-user.html文件。不知道为什么没有发生这种情况。
请建议
您想将URI http://3.121.253.126:8080/指向位于/signup
的文件
使用Nginx有很多方法可以实现,包括/etc/nginx/html/add-user.html
和rewrite
指令。
例如:
try_files
location /signup {
try_files /add-user.html =404;
}
指令不需要在此root
块中重复,因为它将从周围的块继承相同的值。
由于location
始终存在,=404
什么都不做,但add-user.html
需要两个参数。有关详细信息,请参阅try_files
。
上述位置将处理以this document开头的任何请求(例如/signup
或/signup/
)。
要将其限制为单个URI /signups
,请使用/signup
修饰符。有关详细信息,请参阅=
。
例如:
this document