0196.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Web Based VSCode with code-server</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="VSCode,Code Server,Debian,HowTo,i12bretro,GitHub,Tutorial,Browser,Tool,Development,Developer,PHP,Proxy,Apache2">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Web Based VSCode with code-server">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  12. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  13. <script type="text/javascript" src="includes/js/steps.js"></script>
  14. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  15. </head>
  16. <body>
  17. <div id="gridContainer">
  18. <div class="topMargin"></div>
  19. <div id="listName" class="topMargin">
  20. <h1>Web Based VSCode with code-server</h1>
  21. </div>
  22. <div></div>
  23. <div id="content">
  24. <h2>Installing code-server</h2>
  25. <ol>
  26. <li>Log into the Linux device</li>
  27. <li>Run the following commands in a terminal:
  28. <div class="codeBlock"># download the code-server install.sh<br />
  29. wget https://code-server.dev/install.sh<br />
  30. # make it executable<br />
  31. chmod +x ./install.sh<br />
  32. # run the installer<br />
  33. sudo ./install.sh --prefix=/usr/local<br />
  34. # start the service as root<br />
  35. sudo su<br />
  36. sudo systemctl enable --now code-server@$USER<br />
  37. exit<br />
  38. # edit the config.yaml<br />
  39. sudo nano /root/.config/code-server/config.yaml</div>
  40. </li>
  41. <li>Edit the password, or change the authentication type to none and change the bind-addr to bind-addr: 127.0.0.1:8888</li>
  42. <li>Continue with the following command in terminal:
  43. <div class="codeBlock"># restart code-server service<br />
  44. sudo systemctl restart code-server@root.service</div>
  45. </li>
  46. <li>Launch on web browser on the host running code-server and navigate to http://DNSorIP:8888</li>
  47. <li>Browser based VS Code......pretty nice</li>
  48. </ol>
  49. <p>Out of the box, code-server is only reachable from the host that it is installed on. An easy to configure workaround is to setup a proxy server to allow requests to Apache/NGINX to be routed to code-server.</p>
  50. <h2>Apache Proxy Server (optional, but recommended)</h2>
  51. <ol>
  52. <li>Run the following commands in terminal:
  53. <div class="codeBlock"># install apache httpd<br />
  54. sudo apt install apache2<br />
  55. # enable headers, rewrite, proxy and proxy_http modules<br />
  56. sudo a2enmod proxy proxy_http rewrite headers proxy_wstunnel<br />
  57. # edit the default site<br />
  58. sudo nano /etc/apache2/sites-available/000-default.conf</div>
  59. </li>
  60. <li>Paste the following configuration into the existing VirtualHost
  61. <p>&lt;location /code&gt;<br />
  62. RewriteEngine On<br />
  63. RewriteCond %{REQUEST_FILENAME} !-f<br />
  64. RewriteCond %{REQUEST_URI} !(.*)/$<br />
  65. RewriteRule ^(.*)$ http://%{HTTP_HOST}/code/ [L,R=301]<br />
  66. &lt;/location&gt;<br />
  67. <br />
  68. &lt;location /code/&gt;<br />
  69. Header set X-Frame-Options ALLOWALL<br />
  70. RewriteEngine On<br />
  71. RewriteCond %{HTTP:Upgrade} =websocket [NC]<br />
  72. RewriteRule /(.*) ws://127.0.0.1:8888/$1 [P,L]<br />
  73. ProxyPreserveHost on<br />
  74. ProxyPass http://127.0.0.1:8888/<br />
  75. ProxyPassReverse http://127.0.0.1:8888/<br />
  76. &lt;/location&gt;</p>
  77. </li>
  78. <li>Press CTRL+O, Enter, CTRL+X to write the changes to code-server.conf</li>
  79. <li>Continue with the following commands in terminal:
  80. <div class="codeBlock"># restart the apache service<br />
  81. sudo systemctl restart apache2</div>
  82. </li>
  83. <li>Back in the web browser, navigate to http://DNSorIP/vscode</li>
  84. <li>Enjoy your web based VS Code</li>
  85. </ol>
  86. <p>Source: <a href="https://github.com/cdr/code-server" target="_blank">https://github.com/cdr/code-server</a><br />
  87. Proxy resource: <a href="https://github.com/cdr/code-server/issues/282" target="_blank">https://github.com/cdr/code-server/issues/282</a></p>
  88. </div>
  89. </div>
  90. </body>
  91. </html>