Nginx代理设置

添加Nginx.conf配置

添加虚拟机配置

touch /etc/nginx/conf.d/cockpit.yunwisdom.club

修改Nginx.conf配置

map $http_upgrade $connection_upgrade { default upgrade; '' close; }
 
upstream websocket {
server 127.0.0.1:9090;
}
 
server{
    listen 80;
    server_name your_domain_host;
    return 301 https://$server_name$request_uri;
}
 
server {
    listen 443 ssl http2;
    server_name your_domain_host;
 
    #ssl on;
    ssl_certificate /etc/nginx/cert/your_domain_host.pem;
    ssl_certificate_key /etc/nginx/cert/your_domain_host.key;
 
    location / {
        root /;
        index index.html;
        proxy_redirect off;
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
    }
}

重启Nginx

先检查nginx配置是否有效/无有异常,如果有异常请按照异常提示修改;使用nginx -t进行nginx.conf的配置检测

nginx -t

重启nginx

nginx -s reload

重启下Nginx,nginx代理的工作就完成了。

异常情况

这时输入域名,能看到登录页面,但登录后,显示不出内容,页面全白。

解决方法:

这里要对cockpit.conf进行设置修改

nano /etc/cockpit/cockpit.conf

参照如下配置修改,注意域名替换为your_domain_host:

[WebService]
Origins = https://your_domain_host https://127.0.0.1:9090
ProtocolHeader = X-Forwarded-Proto
AllowUnencrypted = true

重启Cockpit
最后重启下cockpit,刷新页面,就一切正常了。

systemctl restart cockpit