gpt4 book ai didi

ubuntu - 无法在 nginx 中配置 proxy_pass

转载 作者:行者123 更新时间:2023-12-04 19:09:56 24 4
gpt4 key购买 nike

我想将请求传递给 HTTP 代理服务器,proxy_pass 指令是在一个位置内指定的。

在我的/etc/nginx/nginx.conf我配置:

server { location ~ ^/api/(.*)$ {

listen 80;
listen [::]:80;
location ~ ^/api/(.*)$ {
proxy_pass 127.0.0.1:8080;
}
}
}

当我执行这个命令时 service nginx start :
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
systemctl status nginx.service 的输出
 ● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2019-11-02 20:25:51 UTC; 53s ago
Docs: man:nginx(8)
Process: 12219 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 9516 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 11760 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 27870 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 11763 (code=exited, status=0/SUCCESS)

Nov 02 20:25:51 ubuntu-s-milos2611 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 02 20:25:51 ubuntu-s-milos2611 nginx[27870]: nginx: [emerg] invalid URL prefix in /etc/nginx/nginx.conf:72
Nov 02 20:25:51 ubuntu-s-milos2611 nginx[27870]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 02 20:25:51 ubuntu-s-milos2611 systemd[1]: nginx.service: Control process exited, code=exited status=1
Nov 02 20:25:51 ubuntu-s-milos2611 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 02 20:25:51 ubuntu-s-milos2611 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

最佳答案

您必须在 proxy_pass 指令中使用 http://前缀:

proxy_pass http://127.0.0.1:8080;

查看 http://nginx.org/en/docs/http/ngx_http_proxy_module.html更多细节。

关于ubuntu - 无法在 nginx 中配置 proxy_pass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58673143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com