내 애플리케이션을 호스팅하기 위해 ASP.NET Core 환경을 설정하려고 하는데 nginx 웹 서버에 문제가 있습니다. 내 도메인에 연결하려고 하면 502 Bad Gateway
. Nginx는 kestrel의 프록시 서버로 실행되어야 합니다.
여기내가 따르고 있는 가이드에 대한 링크입니다. 구성은 Microsoft에서 제안한 구성과 거의 같습니다. 각 환경마다 다른 변수를 변경했을 뿐입니다.
문제가 되는 줄은 http://aspdotnethost;
nginx.conf 구성의 끝에 있습니다. 주석을 달면 기본 www 위치로 리디렉션됩니다.
그러면 해당 라인이 실제로 어떻게 작동하며 localhost:5000 으로 올바르게 리디렉션되도록 어떻게 관리할 수 있습니까?
/etc/nginx/proxy.conf
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;
/etc/nginx/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
.