nginx+vaadin配置

nginx+Vaadin的特殊性在于配置WEBSOCKET或LONG_POLLING。网上资料不多,自己多次尝试配置都不成功,后来终于找到这篇说明才得以配置成功,使用效果不错,介绍如下。

1、/etc/nginx/nginx.conf

map $http_upgrade $connection_upgrade {
    default Upgrade;
    ''      close;
}

2、/etc/nginx/conf.d/default.conf

server {
    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_buffering off;
        proxy_ignore_client_abort off;
        proxy_read_timeout 84600s;      # 1 day
        proxy_send_timeout 84600s;      # 1 day
        #break;
    }
}

完成配置,重启nginx即可。

另请参见:http://atmosphere-framework.2306103.n4.nabble.com/Nginx-and-Atmosphere-td4119410.html