[英]Nginx docker - basic nginx.conf file to accept HTTPS
I am spinning up a dev environment for an application using docker/docker-compose.我正在使用 docker/docker-compose 为应用程序构建开发环境。 I am attempting to set up the app to accept HTTPS protocol (for dev a self-signed cert using openssl is sufficient) but am having issues.
我正在尝试将应用程序设置为接受 HTTPS 协议(对于开发人员来说,使用 openssl 的自签名证书就足够了)但我遇到了问题。
My docker-compose
file (note I am mounting volumes for the certs as well as the nginx.conf file shared below):我的
docker-compose
文件(注意我正在安装证书的卷以及下面共享的 nginx.conf 文件):
services:
nginx:
image: nginx:latest
container_name: webserver
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- /homes/edmisml/nginx_docker_vol/nginx.conf:/etc/nginx/nginx.conf
- /etc/ssl:/ssl/
myservice:
build: ./erschatbot_frontend
restart: unless-stopped
expose:
- 8080
My very simple nginx.conf to allow HTTPS so far:到目前为止,我非常简单的 nginx.conf 允许 HTTPS :
http {
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /ssl/private/nginx-selfsigned.key;
access_log /var/log/nginx/data-access.log combined;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $host;
}
}
}
When I spin up the containers using docker-compose I get the following error当我使用 docker-compose 启动容器时,出现以下错误
webserver | 2021/03/09 14:53:27 [emerg] 1#1: unexpected "}" in /etc/nginx/nginx.conf:26
webserver | nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:26
So I assume this is a syntax error but I do not see the particular issue.所以我认为这是一个语法错误,但我没有看到特定的问题。 For reference I am roughly following the guide here .
作为参考,我大致遵循此处的指南。
I am a total nginx noob - can someone help me out?我是一个总 nginx 菜鸟 - 有人可以帮帮我吗?
UPDATE: fixed silly typo at line 25 (missing semi-colon) but am still receiving errors when visting the https:<url>
.更新:在第 25 行修复了愚蠢的错字(缺少分号),但在访问
https:<url>
时仍然收到错误。 Error:错误:
webserver | 2021/03/09 15:31:44 [error] 32#32: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 10.75.226.54, server: example.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "example.com"
Is it possible that you missed this?你有可能错过了这个吗?
http {
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /ssl/private/nginx-selfsigned.key;
access_log /var/log/nginx/data-access.log combined;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $host; // <--- here
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.