Nginxのファイル設定についてサイトの情報などを取り入れていましたが、かなり混乱してしまい疑問点(わからないポイント)を質問させて頂きました。たぶん間違いだらけだと思いますが、以下のように3つのファイルを作成しています。
/etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; location / { root /usr/share/nginx/html/current/public; index index.html index.htm; } error_page 500 502 504 /50x.html; location = /50x.html { root /usr/share/nginx/html/public; } }
/etc/nginx/conf.d/https.conf map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 443 ssl http2; server_name XXX-XXX.com; location / { root /usr/share/nginx/html/current/public; index index.html index.htm; } ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EECDH+AES; ssl_ecdh_curve prime256v1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/letsencrypt/live/XXX-XXX.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/XXX-XXX.com/privkey.pem; error_page 500 502 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
/etc/nginx/conf.d/reils.conf upstream unicorn { server unix:/usr/share/nginx/html/current/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name XXX-XXX.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; root /usr/share/nginx/html/current/public; proxy_connect_timeout 60; proxy_read_timeout 60; proxy_send_timeout 60; client_max_body_size 100m; error_page 404 /404.html; error_page 500 502 504 /500.html; try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://unicorn; } set $maintenance false; if ( -f $document_root/tmp/maintenance.html ) { set $maintenance true; } if ( $args ~ "mode=hogehoge" ) { set $maintenance false; } location @maintenance { try_files /tmp/maintenance.html /maintenance.html; } location /healthcheck { if ( $maintenance = true ) { return 200; } } location / { index index.html; if ( $maintenance = true ) { error_page 503 @maintenance; return 503; } try_files $uri @app; } location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } }
疑問点は以下になります。
ファイルを3つ準備しました。ファイルごとに同じコード(重複したコード)を記述したりしてますが 重複したコードは、どれか1つのファイルにのみ記述し、他のファイルには重複したコードは 記述せず削除するべきなのでしょうか?
server_name には何を記述すればいいのでしょうか? ・default.confの listen 80;のところではserver_name localhost ・https.confのlisten 443 ssl http2;のところではXXX-XXX.com (自分のドメイン名) ・rails.confのlisten 80;のところではXXX.XXX.XX.XX (VPSのIPアドレス) 3つのファイルにそれぞれ異なる記述をしています。統一するべきなのでしょうが、どれを記述すればいいのかご教示お願いします。 ここも、重複していれば削除するべきでしょうか?
/etc/nginx/conf.d/reils.conf が一番ゴチャゴチャしていて不明点の多いファイルです。 1,error_page 500 502 504 /500.html; ここで503はメンテナンス画面表示のため削除しました。これは正解なのでしょうか? 2,try_files $uri/index.html $uri @unicorn; ここの@unicornの部分は何を記述するべきなのでしょうか? ・作業用ユーザー名(# adduser panda で作業用ユーザーを作成しました)@pandaと記述なのでしょうか? それとも、他に記述するべき名称(ディレクトリ名、ファイル名、アプリ名)があるのでしょうか? (# pwd と打ち込むと /home/panda と出てきます。) 3,proxy_pass http://unicorn; 上の質問と重複していそうなのですが、ここもunicornではなくpandaとするべきなのでしょうか?
4,maintenanceの設定のところについても現在@appなどとしていますが、@pandaにするべきでしょうか?
このファイルは複数のサイトの内容を参考にして記述してしまっているので、たぶん設定がメチャクチャなのだと思います。
2~4までの問題は理解できた感じです。(たぶん以下でしょう)
try_filesの@unicornは直下のlocation @unicornを指していて、その中のproxy_pass http://unicornのunicornはupstream unicornを指しているようです。
初めてのデプロイ、Nginxの設定で知っている人からみたら笑えるくらい変な設定になっていると思いますが、なにとぞご教示の程宜しくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。