AWSでdjangoとgunicorn、nginxを使ってWebサーバーを立ち上げたいと思っています。
【AmazonLinux2でDjangoの本番環境構築】Python3.8,Nginx,Gunicorn,PostgreSQLを参考にさせて頂き、EC2へグローバル直アドレスで閲覧できるところまではできました。
HTTPS化するところからは、AWSのCertificate ManagerとALBを使おうと思って、証明書の発行を行いALBを設定して、ALBのDNSアドレスをRoute53で設定して逆引きできることを核にしています。
EC2はPrivateSubnetとしてALBとのHTTPで通信できるようにセキュリティポリシーを作っています(確認のためmyIPのみでSSHとHTTPを許可を設定)。
しかし、この状態でもEC2は直アドレスで問題なく表示できるのですが、ALBを経由するDNS名ではエラー400となってしまいます。
nginxのログではALBからルートディレクトリへのアクセスでエラーとなり、myIPも表示されています。
最初はHealthCheckも400だったのですが、nginx.confにダミーを設けることでクリアしましたが、やはりルートディレクトリに対しては依然として400でした。
色々なサイトで調べて施してみましたが解決できず、ご教授頂ければと思いました。
これまで別の形でのALBを使ったWebサーバーは立ててきたのですが、こんなにつながらないのは初めてです。
nginx.confは以下の通りです。
# * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; listen [::]:80; server_name <My domain>; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location /.well-known/acme-challeng { root /usr/share/nginx/html; } location /healthcheck { empty_gif; access_log off; break; } location /static { #.htmlは省略できる try_files $uri $uri/ $uri.html =404; } location /media { } location / { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:8000; } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } #443の記述はすべてコメントアウトのまま }
どうすれば表示できるのかご教授ください。
あなたの回答
tips
プレビュー