
Docker 프로젝트의 Nginx에 문제가 있습니다. 여기에 비슷한 게시물이 많이 있지만 저를 도와줄 수 있는 게시물이 없다는 것을 알고 있습니다.
저는 Docker와 함께 Nginx를 사용하고 있으며 웹 사이트는 작동하지만 일부 확장 및 보안 기능을 추가하고 성능을 위해 작성된 코드를 개선하고 싶었습니다. 이를 위해 http 블록을 추가하고 이벤트 블록을 정의하고 싶습니다.
해당 항목을 추가하려고 하면 다음 오류가 발생합니다.
[emerg] 7#7: "events" directive is not allowed here in /etc/nginx/conf.d/app.conf:1
또는 이벤트 섹션을 제거하면 다음과 같습니다.
[emerg] 7#7: "http" directive is not allowed here in /etc/nginx/conf.d/app.conf:13
어떤 이유로 /etc/nginx/ 디렉토리에 sites-enabled 폴더와 sites-available 폴더가 없습니다. 이것이 중요한지 모르겠습니다.
그러나 내 app.conf 파일은 다음과 같습니다(문제 없이 작동함).
#events {
# worker_processes auto;
# worker_connections 1024;
# worker_rlimit_nofile 2048;
# multi_accept on;
# mutex_accept on;
# mutex_accept_delay 500ms;
# use epoll;
# epoll_events 512;
#}
#http {
#access_log logs/access.log combined;
#error_log logs/warn.log warn;
upstream app {
least_conn;
server app_2:8001;
server app_2:443;
server app:8000;
server app:443;
}
server {
listen 80;
server_name find-your-spirits.de;
location / {
return 301 https://$host$request_uri;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name find-your-spirits.de;
location / {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /staticfiles/ {
alias /app/staticfiles/;
add_header Access-Control-Allow-Origin *;
}
ssl_certificate /etc/letsencrypt/live/find-your-spirits.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/find-your-spirits.de/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
#}
#을 제거하면 앞서 언급한 오류가 발생합니다.
이것은 내 Dockerfile입니다.
FROM nginx:1.19.0
RUN rm /etc/nginx/conf.d/default.conf
COPY app.conf /etc/nginx/conf.d
이것은 내 docker-compose 파일입니다.
version: '3'
services:
app:
image: django
build:
context: ./app
dockerfile: Dockerfile
env_file:
- ./.test.env
volumes:
- ./app/:/app/
- ./app/staticfiles/:/app/staticfiles
- ./data/.htpasswd:/etc/nginx/.htpasswd
command: gunicorn --bind 0.0.0.0:8000 --chdir /app/ Webserver.wsgi
app_2:
image: django
build:
context: ./app
dockerfile: Dockerfile
env_file:
- ./.test.env
volumes:
- ./app/:/app/
- ./app/staticfiles/:/app/staticfiles
- ./data/.htpasswd:/etc/nginx/.htpasswd
command: gunicorn --bind 0.0.0.0:8001 --chdir /app/ Webserver.wsgi
nginx:
image: nginx:1.19.0
build:
context: ./data/nginx
dockerfile: Dockerfile
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./app/staticfiles/:/app/staticfiles
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
- ./data/.htpasswd:/etc/nginx/.htpasswd
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.test.env
environment:
- POSTGRES_DB_PORT=${SQL_PORT}
- POSTGRES_DB_HOST=${SQL_HOST}
- POSTGRES_PASSWORD=${SQL_PASSWORD}
- POSTGRES_USER=${SQL_USER}
- POSTGRES_DB=${SQL_DATABASE}
ports:
- 5432:5432
volumes:
postgres_data
더 많은 정보나 다른 파일의 내용이 필요하시면 댓글을 남겨주시면 나중에 추가하겠습니다.
또한 저는 Nginx를 처음 접했기 때문에 잘못 작성된 내용을 발견하면 자유롭게 수정하거나 개선할 수 있습니다.