Home > OS >  how to convert nginx config file from code-server to apache2 config file
how to convert nginx config file from code-server to apache2 config file

Time:11-06

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

CodePudding user response:

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 />

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 />

CodePudding user response:

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>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related