我试图使用nginx使用HTTP / 2反向代理服务我的Polymer PWA,但我无法让它正常工作。 PWA与prpl-server在127.0.0.1:38765非捆绑服务,工作正常。我的prpl-server看起来像这样:
const express = require('express')
const prpl = require('prpl-server')
const config = require('./build/polymer.json')
const app = express()
const port = 38765
app.get('*', prpl.makeHandler('./build/', config))
app.listen(port)
我在/etc/nginx/sites-available/default
的nginx配置如下所示:
upstream app {
server 127.0.0.1:38765;
keepalive 64;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name app; # or full domain? tried both, doesn't work
location / {
proxy_pass http://app$request_uri;
proxy_redirect off;
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_set_header X-Forwarded-Proto-Version $http2;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
# Cache Controls
# This section sets response expiration which prevents 304 not modified
expires 0;
add_header Pragma public;
add_header Cache-Control "public";
access_log off;
# Security Patches
# This section are security patches in case the client overrides
# these values, the server re-enables it and enforce its rules
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "deny";
add_header X-Content-Type-Options "nosniff";
}
ssl on;
ssl_session_cache shared:SSL:5m;
ssl_session_timeout 1h;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
}
当我转到页面时,除了ma-app.html
(应用程序shell)之外,所有依赖项似乎都是通过h2下载的,这给了我502错误。所有其他文件以200状态下载并具有相同的大小(减去一些压缩),就像我直接转到端口38765,但页面是空白的。
我错过了什么吗?为什么shell没有正确下载?所有文件'请求URL对于nginx反向代理与prpl-server完全相同,但端口号除外。
答案 0 :(得分:1)
这个问题与缓冲区大小太小有关,如下所述:https://github.com/Polymer/prpl-server-node/issues/50#issuecomment-333270848。
我添加了
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
在nginx配置的location
部分,现在可以了。