gpt4 book ai didi

docker - Nginx没有Docker连接到Docker容器(clojure)

转载 作者:行者123 更新时间:2023-12-02 19:19:37 27 4
gpt4 key购买 nike

我是webapps和nginx的新手。
我的default.conf看起来像这样

  listen 80;

return 301 https://$host$request_uri;

}

server {
server_name <my-domain-name>;

location / {
root /usr/share/nginx/html;
index index.html;
}

location /static {
root /usr/share/nginx/html;
}

location /api {
proxy_pass http://<my-container-name>:8080/api;

# tell http-kit to keep the connection
proxy_http_version 1.1;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}


listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live//fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live//privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
if ($host = <my-domain>) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
server_name <my-domain>;
return 404; # managed by Certbot


}

我在一个 digital ocean ubuntu实例中运行nginx。我也有一个运行mye clojure http-kit webapp的docker容器。它正在侦听端口8080。它具有/ api / chsk / api / login / api / signup之类的路由。

我使用此脚本运行图像
#!/bin/sh
docker kill my-container
docker rm my-container
docker build -t my-image ~/my-project
docker run -p 8080:8080 --name my-container -d my-image

这曾经可以工作,但是现在在运行systemctl start nginx时出现以下错误:
  Process: 16899 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 16505 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=1/FAILURE)
Process: 16850 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 19501 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 16853 (code=exited, status=0/SUCCESS)

Mar 22 09:08:00 systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 22 09:08:00 nginx[19501]: nginx: [emerg] host not found in upstream "my-container" in /etc/nginx/conf.d/default.conf:21
Mar 22 09:08:00 nginx[19501]: nginx: configuration file /etc/nginx/nginx.conf test failed
Mar 22 09:08:00 systemd[1]: nginx.service: Control process exited, code=exited status=1
Mar 22 09:08:00 systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 22 09:08:00 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

需要明确的是,我没有在docker中运行nginx。我同时提供静态内容。

最佳答案

它可以使用lein run在正确的端口上运行。感谢@ErwinRooijakkers。我将proxy_pass更改为localhost:8080 / api,它起作用了!谢谢。不确定为什么它不能与容器一起使用,因为它以前可以工作...

关于docker - Nginx没有Docker连接到Docker容器(clojure),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60797641/

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