0196.html 4.2 KB

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