I'm new to webapps and nginx in particular. My default.conf looks like this
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
}
I have nginx running inside a digital ocean ubuntu instance. I also have a docker container running mye clojure http-kit webapp. It's listening on port 8080. It has routes such as /api/chsk /api/login /api/signup.
I run the image with this script
#!/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
This used to work, but now I get the following error when running 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.
To be clear, I'm not running nginx inside docker. I'm serving static content at the same time.
It was able to run on the correct port using lein run. thanks to @ErwinRooijakkers . I changed my proxy_pass to localhost:8080/api and it worked! thank you. Not sure why it didn't work with the container, since it worked before...