我正在使用 Angular 4.1.0 进行 MEAN 项目开发。在本地主机上,一切顺利没有错误。但是当我部署到服务器时,检索带有超过8个问题/答案对的用户会导致 xhr 请求出现 net::ERR_CONNECTION_CLOSED 错误。我使用的digital ocean droplet上使用了nginx反向代理,并使用letsencrypt SSL证书。 我已经尝试了以下方法:
- 重启服务器、nginx服务、node.js等。
- 在nginx配置文件中将
client_max_body_size
增加到20M
- 在nginx配置文件中将
large_client_header_buffers
的大小增加到128k
- The
GET
request toqapairs?jwt=ey..
never reaches the node.js app - There is no mention of the request in
/var/log/nginx/error.log
The failing requests shown in the
/var/log/nginx/access.log
are as follows:89.15.159.19 - - [08/May/2017:14:25:53 +0000] "-" 400 0 "-" "-" 89.15.159.19 - - [08/May/2017:14:25:53 +0000] "-" 400 0 "-" "-"
Chrome开发者工具网络选项卡截图
在登录只有7个问题答案对的账户后
然后,前往mlab.com并手动添加另一个问题答案对到同一帐户,然后刷新页面(请注意现在有8个问题)
最后,在同一帐户中登录和退出后(请注意xhr请求到
qapairs?jwt=ey...
返回失败状态)
/etc/nginx/sites-enabled/default
# HTTP — redirect all traffic to HTTPS server { listen 80; listen [::]:80 default_server ipv6only=on; return 301 https://$host$request_uri; } # etc # HTTPS ^ ^ proxy all requests to the Node app server { # Enable HTTP/2 listen 443 ssl http2; listen [::]:443 ssl http2; server_name subdomain.example.com; # Use the Let ^ ^ s Encrypt certificates ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # Include the SSL configuration from cipherli.st include snippets/ssl-params.conf; # Increase allowed URL length large_client_header_buffers 4 128k; # Increase max body size client_max_body_size 20M; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://subdomain.example.com:3001/; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; proxy_redirect off; } }
qa-pairs.service.ts
The error is being caught here in the
getQAPairs
function. Being passed to the callback in thecatch
function aProgressEvent
object with atype
property oferror
,eventPhase
of2
.
@Injectable() export class QaPairsService { /* etc */ getQAPairs () { const jwt = localStorage.getItem('jwt') ? `?jwt=${localStorage.getItem('jwt')}` : '' return this.http.get(this.qapairsUrl + jwt) .map(response => { this.qapairs = response.json().map((qapair: IQAPair) => new QAPair(qapair)) this.qapairsChanged.emit(this.qapairs) return this.qapairs }) .catch( (error: any) => { error = error.json() this.errorsService.handleError(error) return Observable.throw(error) } ) } /* etc */ }