我正在尝试为websockets配置nginx。但它返回一个错误。[emerg] 8#8: invalid number of arguments in "proxy_set_header" directive in /etc/nginx/conf.d/default.conf:45 nginx: [emerg] directive in /etc/nginx/conf.d/default.conf:45
第45行出现错误,即:proxy_set_header Upgrade $http_upgrade;
我不知道为什么它不工作,我从nginx docs复制它。
寻找解决方案我尝试在$前加一个\,切换nginx版本。
没用
location /ws/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
default.conf -完整配置文件
upstream frontend {
server frontend:3000;
}
upstream backend {
server backend:8000;
}
server {
listen 80;
listen [::]:80;
server_name ${DOMAIN} www.${DOMAIN};
location /.well-known/acme-challenge/ {
root /vol/www/;
}
location / {
return 301 https://${DOMAIN}$request_uri;
}
}
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
server_name ${DOMAIN} www.${DOMAIN};
ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem;
include /etc/nginx/options-ssl-nginx.conf;
ssl_dhparam /vol/proxy/ssl-dhparams.pem;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location /api/ {
proxy_pass http://backend;
proxy_redirect off;
}
location /ws/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
proxy_pass http://frontend;
proxy_redirect off;
client_max_body_size 10M;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
你知道我该怎么做才能让它正常工作吗?
1条答案
按热度按时间kq4fsx7k1#
我想我可以把
proxy_set_header
放到另一个文件中,然后使用include。我创建了一个名为
proxy_params
的文件,其中包含以下内容proxy_params
然后在配置文件中使用
include /etc/nginx/proxy_params;
这就是我的websockets配置的样子
default. conf-websocket config