coder-server服务器部署问题(500错误)

服务器:阿里云
版本:Ubuntu 18.04 64位
时间:2020年04月07日
code-server版本:3.0.2node


image.png
项目搭建完后,访问地址,遇到上述状况,如下是解决过程nginx

解决过程

首先在终端中输入./coder-server --help能够看到code-server支持的命令docker

Options
      --auth                The type of authentication to use. [password, none]
      --cert                Path to certificate. Generated if no path is provided.
      --cert-key            Path to certificate key when using non-generated cert.
      --disable-updates     Disable automatic updates.
      --disable-telemetry   Disable telemetry.
      --host                Host for the HTTP server.
   -h --help                Show this output.
      --open                Open in browser on startup. Does not work remotely.
      --port                Port for the HTTP server.
      --socket              Path to a socket (host and port will be ignored).
   -v --version             Display version information.
      --disable-ssh         Disable the SSH server.
      --ssh-host-key        SSH server host key.
      --user-data-dir       Path to the user data directory.
      --extensions-dir      Path to the extensions directory.
      --list-extensions     List installed VS Code extensions.
      --force               Avoid prompts when installing VS Code extensions.
      --install-extension   Install or update a VS Code extension by id or vsix.
      --uninstall-extension Uninstall a VS Code extension by id.
      --show-versions       Show VS Code extension versions.
 -vvv --verbose             Enable verbose logging.

看到最后一行--verbose Enable verbose logging.
能够经过--verbose来查看日志,在启动的时候添加这个参数,访问,而后就能够看到如下输出ubuntu

debug URIError: URI malformed
    at decodeURI (<anonymous>)
    at /var/local/vscode/code-server/out/node/http.js:297:35
    at Array.forEach (<anonymous>)
    at VscodeHttpProvider.HttpProvider.parseCookies (/var/local/vscode/code-server/out/node/http.js:292:47)
    at VscodeHttpProvider.HttpProvider.authenticated (/var/local/vscode/code-server/out/node/http.js:239:36)
    at VscodeHttpProvider.<anonymous> (/var/local/vscode/code-server/out/node/app/vscode.js:208:40)
    at step (/var/local/vscode/code-server/out/node/app/vscode.js:46:23)
    at Object.next (/var/local/vscode/code-server/out/node/app/vscode.js:27:53)
    at /var/local/vscode/code-server/out/node/app/vscode.js:21:71
    at new Promise (<anonymous>)

初步查看是decodeURI方法报错了
看到第三行:at /var/local/vscode/code-server/out/node/http.js:297:35
定位到文件里centos

HttpProvider.prototype.parseCookies = function (request) {
    var cookies = {};
    if (request.headers.cookie) {
        request.headers.cookie.split(";").forEach(function (keyValue) {
            var _a = util_1.split(keyValue, "="), key = _a[0], value = _a[1];
            if (!cookies[key]) {
                cookies[key] = [];
            }cookies
            [key].push(decodeURI(value));
        });
    }
    return cookies;
};

报错是decodeURI(value)报错致使的,
搜索decodeURI报错缘由
看到有说:因为decodeURI转码时,经过%进行解析,若是字符串中存在%(如: ‘0.9%氯化钠注射液’),则会出现URI malformed
而value的值是从cookie中获取的
查看cookie,发现有好几个值是带有%号的
所有清除后,刷新页面
成功访问浏览器


缘由

阿里云服务器是有镜像市场的,以前在服务器上装了个宝塔的镜像系统,他应该是在cookie写进了一些信息,带有%号的cookie,致使上述结果。换系统,使用docker,都没法解决,由于换系统浏览器上cookie也仍是一直存在,因此仍是没法正常访问的安全


曲折过程

  1. 重装系统:怀疑是系统问题,换成阿里云自带的ubuntu 1四、ubuntu 16,ubuntu 18, centos,仍是镜像市场里的系统,重装系统好几回均无效果
  2. 使用docker:同样的报错
  3. 不使用密码登陆:添加指令--auth none能够正常访问,可是这样谁均可以访问你的服务,这样是不安全的,想到一个方法:就是在添加的安全组仅添加我本身本地的ip,这样就能够保证我本身的网络能够访问。可是这样的话,要是换个网络,那就又得新添加安全组,极其不方便。
  4. ip访问,输入的地址太繁琐,改用域名访问:nginx配置proxy_pass http://localhost:8081/,这样直接访问域名,就能够访问到项目了,可是后来才发现这样谁均可以直接经过域名访问项目,以前设置的安全组是对如今这个作法无效的。
  5. 域名访问的时候,添加密码验证。配置后发现没法正常访问

总结

解决问题,要学会从源头上解决,刚开始不知道怎么看日志,没法定位到问题出现的源头,后来定位到源头后,立马就解决了,虽然解决这个的过程比较曲折,可是不断重装系统,对服务器的了解更近了一步,也不算白费力气。服务器

相关文章
相关标签/搜索