我有一台 VPS Linux(Ubuntu)服务器,我想通过 nginx 将域名与我的服务器 IP 连接起来,但 nginx 不起作用。我已检查以下内容:
$ sudo systemctl reload nginx
nginx.service is not active, cannot reload
$ sudo service nginx start
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-05-15 18:53:40 CEST; 11s ago
$ sudo nginx -t
nginx: [emerg] unknown "connection_upgrade" variable
nginx: configuration file /etc/nginx/nginx.conf test failed
关于在我自己的域上运行应用程序,我有一个 nginx 配置文件:
$ sudo cat /etc/nginx/sites-available/shiny
server {
server_name my_domain.com;
location / {
proxy_pass http://localhost:80;
proxy_redirect / $scheme://$http_host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
}
如果有人能帮助我解决这个问题我将不胜感激。
答案1
只需用这个proxy_set_header Upgrade $http_upgrade;
替换/etc/nginx/sites-available/shiny
:
proxy_set_header Connection "upgrade";
然后运行nginx -t
测试配置文件,如果一切正常的话,输出应该是这样的:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
然后运行nginx -s reload
,这样 nginx 将动态更新配置。
并且不要忘记删除它proxy_redirect / $scheme://$http_host/;
并 listen 4444
在服务器块末尾添加一个来指定监听端口。