0

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

2 Answers2

0

I believe the following should work:

<VirtualHost _default_:80>
ServerName myserverdomainname
ServerAdmin webmaster@myserverdomainname
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
RequestHeader set Connection ""
RequestHeader set Upgrade $http_upgrade;
RequestHeader set Connection "upgrade"
RequestHeader set X-Forwarded-Proto "http"
<Location />
</VirtualHost>

SSL Enabled

<VirtualHost _default_:443>
ServerName myserverdomainname
ServerAdmin webmaster@myserverdomainname
SSLEngine on
SSLProxyEngine on
##LE Certs
SSLCertificateFile /etc/letsencrypt/live/domain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/domain/fullchain.pem
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
RequestHeader set Connection ""
RequestHeader set Upgrade $http_upgrade;
RequestHeader set Connection "upgrade"
RequestHeader set X-Forwarded-Proto "https"
<Location />
</VirtualHost>
casjay
  • 1
  • 1
  • 2
  • Thank you very much for your answer and should I put both virtual hosts for http and https in the same file? And you closed the tag with is it normal that it is not ? – Indy Stracky Nov 06 '21 at 08:34
  • You can use both, however, if your site is configured to redirect http to https then only the https virtual host is needed. Also close the virtual host with – casjay Nov 11 '21 at 14:56
0

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>