アプリケーションをホストするために ASP.NET Core 環境をセットアップしようとしていますが、nginx Web サーバーで問題が発生しています。ドメインに接続しようとすると、次のエラーが表示されます。Nginx502 Bad Gateway
は、kestrel のプロキシ サーバーとして実行する必要があります。
こここれは私が従っているガイドへのリンクです。構成は、Microsoft が提案する構成とほぼ同じですが、環境ごとに異なる変数を変更しただけです。
問題となっている行は、http://aspdotnethost;
nginx.conf 構成の最後にあります。これをコメントアウトすると、デフォルトの www の場所にリダイレクトされます。
では、この行は実際にどのように機能し、localhost:5000 に適切にリダイレクトするにはどうすればよいでしょうか?
プロキシの設定
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
nginx.conf は、
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
include /etc/nginx/proxy.conf;
limit_req_zone $binary_remote_addr zone=one:10m rate=5r/s;
server_tokens off;
sendfile on;
keepalive_timeout 29; # Adjust to the lowest possible value that makes sense for your use case.
client_body_timeout 10; client_header_timeout 10; send_timeout 10;
upstream aspdotnethost {
server localhost:5000;
}
server {
listen *:80;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://$host$request_uri;
}
server {
listen *:443 ssl;
server_name example.com *.example.com;
#Redirects all traffic
location / {
proxy_pass http://aspdotnethost;
limit_req zone=one burst=10;
}
}
}
Nginx 設定チェック:
[root@rs-zap353479-1 patrick]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
入力するとcurl http://localhost:5000
、HTML ドキュメントが返されます。そのため、そのコンポーネントは私の目には見つかるはずです。
答え1
Eugen Rieck がコメントとして投稿したように、 にエイリアスを追加する必要がありました/etc/hosts
。
proxy_temp_path
追加の手順として、で を指定しproxy.conf
、そのパスを作成して、nginx が実行されているユーザー (私の場合は ) に chown する必要がありますnginx
。