apachenginxhttpsapache2code-server

how to convert nginx config file from code-server to apache2 config file


I come here, because as the title indicates it I installed code-server except that I would like that it goes under apache2 rather than under nginx. I'm trying to set up my server under https, I already have my certificates I just need the configuration file. I'm a beginner so I don't understand everything about how nginx and code-server work and how to adapt it. I followed many tutorials to do this and the configuration file is always the same:

server {
    listen 80;
    listen [::]:80;
    server_name domainname.domain.dev;
    location / {
        proxy_pass http://localhost:8080/;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
    }
}

Before I had to set up the service file: code-server.service:

[Unit]
Description=code-server
After=apache2.service #I changed this line before it was: nginx.service

[Service]
Type=simple
Environment=PASSWORD=code-server-password
ExecStart=/usr/bin/code-server --bind-addr 127.0.0.1:8080 --user-data-dir /var/lib/code-server --auth password
Restart=always

[Install]
WantedBy=multi-user.target

Can you help me ? I'm trying to find a solution to this problem but I don't know how to do it


Solution

  • So finally I found the solution to my problem, I had to use apache reverse proxy. I didn't understand all the code but it works. For those who have the same problem as me, I found this site: https://toscode.gitee.com/crazyleega/code-server/blob/master/doc/quickstart.md

    To activate https and thus ssl, I did this:

    <VirtualHost *:443>
      ServerName domainname
    
      RewriteEngine On
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
      RewriteRule /(.*)           http://localhost:8080/$1 [P,L]
      SSLEngine on
      SSLProxyEngine on
      SSLCertificateFile pathofyourcert
      SSLCertificateKeyFile pathofyourkey
      ProxyRequests off
      ProxyPass        / http://localhost:8080/ nocanon
      ProxyPassReverse / http://localhost:8080/
    </VirtualHost>