我有一个使用Angular6 + Django rest框架开发的Web应用程序,并托管在AWS中。 Angular应用程序已部署到我的公共服务器(ip:3.xx.xx.xx),而Django Api已部署到我的私有服务器(ip:10.xx.xx.xx) 我正在使用nginx将代理从Web服务器反向代理到appserver。从角度应用程序,我正在形成端点来调用api函数。 点击注册后,请求应进行api调用。
角度网址:http://3.xx.xx.xx:8083/signup
Api端点:http://10.xx.xx.xx:8081/api/customer/company_registration/
但是当我单击注册时,我遇到了以下错误:
POST http://10.xx.xx.xx:8081/api/customer/company_registration/
net::ERR_CONNECTION_TIMED_OUT
ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText:
"Unknown Error", url: null, ok: false, …}
error: ProgressEvent {isTrusted: true, lengthComputable: false,
loaded: 0, total: 0, type: "error", …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null,
headers: Map(0)}
message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: null
__proto__: HttpResponseBase
这是我尝试过的nginx配置:
server {
listen 8083;
server_name 3.xx.xx.xx;
client_max_body_size 20m;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
root /usr/share/nginx/html/;
index index.html;
}
}
server {
listen 8081;
server_name 10.xx.xx.xx;
client_max_body_size 20m;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Handles proxying to Django API
location /api/ {
#rewrite ^/api(.*) $1 break;
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT,
DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers'
'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-
Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
proxy_set_header Host $http_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;
proxy_pass http://10.xx.xx.xx:8081;
}
}
我在使用Nginx方面经验不足。感谢您的帮助。 谢谢