服務器:阿里雲
版本:Ubuntu 18.04 64位
時間:2020年04月07日
code-server版本:3.0.2node
項目搭建完後,訪問地址,遇到上述狀況,如下是解決過程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也仍是一直存在,因此仍是沒法正常訪問的安全
proxy_pass http://localhost:8081/
,這樣直接訪問域名,就能夠訪問到項目了,可是後來才發現這樣誰均可以直接經過域名訪問項目,以前設置的安全組是對如今這個作法無效的。解決問題,要學會從源頭上解決,剛開始不知道怎麼看日誌,沒法定位到問題出現的源頭,後來定位到源頭後,立馬就解決了,雖然解決這個的過程比較曲折,可是不斷重裝系統,對服務器的瞭解更近了一步,也不算白費力氣。服務器