Installing code-server v4.99.3 on VPS with NGINX and SSL
user: Can you help me get code the coder code-server v4.99.3 running on my VPS with subdomain code.myconversationswith.ai with Lets Encrypt Certbot?
I already have advanced both ipv4&ipv6 DNS configured with NameCheap
assistant: Yes, Captain. I’ll walk you through getting `code-server` v4.99.3 running on your VPS at `code.myconversationswith.ai`, served securely via NGINX and Let’s Encrypt Certbot (IPv4 & IPv6-ready).
---
## ✅ What This Will Do:
1. Download and install code-server v4.99.3
2. Create a systemd service
3. Set up NGINX as a reverse proxy for `code.myconversationswith.ai`
4. Configure a valid SSL certificate using Certbot
5. Open firewall ports (if UFW is used)
---
## 🚀 Prerequisites:
- Your domain/subdomain `code.myconversationswith.ai` already points to your server (A and AAAA records)
- Ubuntu 22.04+ with root or sudo access
- You want to use the standard `~/code-server` location
---
## ⚙️ INSTALL SCRIPT: `install-code-server.sh`
Create and run this in one command:
```bash
nano ~/install-code-server.sh && chmod +x ~/install-code-server.sh && ~/install-code-server.sh
```
Paste this in:
```bash
#!/bin/bash
set -e
# 1. Install dependencies
sudo apt update
sudo apt install -y curl wget nginx certbot python3-certbot-nginx ufw
# 2. Create code-server user if not exists
id -u codeuser &>/dev/null || sudo useradd -m -s /bin/bash codeuser
# 3. Download code-server v4.99.3
cd /tmp
wget https://github.com/coder/code-server/releases/download/v4.99.3/code-server-4.99.3-linux-amd64.tar.gz
tar -xzf code-server-4.99.3-linux-amd64.tar.gz
sudo mv code-server-4.99.3-linux-amd64 /opt/code-server
# 4. Symlink the binary
sudo ln -sf /opt/code-server/bin/code-server /usr/local/bin/code-server
# 5. Create config file
sudo mkdir -p /home/codeuser/.config/code-server
sudo tee /home/codeuser/.config/code-server/config.yaml > /dev/null <<EOF
bind-addr: 127.0.0.1:8080
auth: password
password: changeme123
cert: false
EOF
sudo chown -R codeuser:codeuser /home/codeuser/.config
# 6. Create systemd service
sudo tee /etc/systemd/system/code-server.service > /dev/null <<EOF
[Unit]
Description=code-server
After=network.target
[Service]
Type=simple
User=codeuser
ExecStart=/usr/local/bin/code-s…
user: yes, but just letting you know that ~/.config/code-server/config.yaml file does not exist
assistant: Thanks for the heads-up, Captain — you're absolutely right. The correct location **when running as user `codeuser`** is:
```
/home/codeuser/.config/code-server/config.yaml
```
The `~/.config` shortcut only resolves properly for the **current user**, so when creating the config for a different user (`codeuser`), we must reference the full path explicitly — which I **already did** in the script:
```bash
sudo tee /home/codeuser/.config/code-server/config.yaml > /dev/null <<EOF
```
So unless `codeuser` wasn’t created properly or the config dir wasn’t written (due to permissions or skipping steps), the file **should** be there after the script finishes.
---
## 🧪 QUICK CHECK:
You can verify it with:
```bash
sudo ls -l /home/codeuser/.config/code-server/config.yaml
```
If it doesn’t exist, rerun just the config creation part:
```bash
sudo mkdir -p /home/codeuser/.config/code-server
sudo tee /home/codeuser/.config/code-server/config.yaml > /dev/null <<EOF
bind-addr: 127.0.0.1:8080
auth: password
password: changeme123
cert: false
EOF
sudo chown -R codeuser:codeuser /home/codeuser/.config
```
---
Would you like me to include a secure random password generator and write it to that file during install?
user: the last time we installed this we didn't have to deal with that. And the code-server ran great right away.
And also, now when i login, I see a pop up saying:
An unexpected error occurred that requires a reload of this page.
The workbench failed to connect to the server (Error: WebSocket close with status code 1006)
sudo ls -l /home/codeuser/.config/code-server/config.yaml
-rw-r--r-- 1 codeuser codeuser 75 Apr 30 11:49 /home/codeuser/.config/code-server/config.yaml
lame, running as codeuser does not do me any much good, why not use my same username I'm using on the server?
assistant: Ahh, got it. Thanks for clarifying — that **WebSocket error 1006** and config confusion tells me everything I need to know.
Let’s fix this **the clean, no-BS way**:
---
## 🧹 Key Issues
1. **WebSocket error 1006** = `code-server` running, but **not reachable via the proxy (NGINX)**, OR it’s being blocked (firewall, wrong bind, wrong user).
2. Running as `codeuser` is unnecessary since you’re the sole admin. It just adds permission friction.
3. Your original setup was **simpler** because it **ran as your main user**, no extra accounts, no funky paths.
---
## ✅ Plan to Reinstall as Your User (e.g., `adam`)
Let’s fix all this:
---
### ✅ 1. Stop & remove old setup
```bash
sudo systemctl stop code-server || true
sudo systemctl disable code-server || true
sudo rm -f /etc/systemd/system/code-server.service
sudo rm -rf /opt/code-server
sudo rm -rf /home/codeuser
sudo userdel -r codeuser || true
```
---
### ✅ 2. Reinstall `code-server` v4.99.3 under your current user (`$USER`)
```bash
cd ~
wget https://github.com/coder/code-server/releases/download/v4.99.3/code-server-4.99.3-linux-amd64.tar.gz
tar -xzf code-server-4.99.3-linux-amd64.tar.gz
sudo mv code-server-4.99.3-linux-amd64 /opt/code-server
sudo ln -sf /opt/code-server/bin/code-server /usr/local/bin/code-server
```
---
### ✅ 3. Create config for your user
```bash
mkdir -p ~/.config/code-server
nano ~/.config/code-server/config.yaml
```
Paste this:
```yaml
bind-addr: 127.0.0.1:8080
auth: password
password: your-strong-password-here
cert: false
```
---
### ✅ 4. Create systemd service under your user
```bash
sudo nano /etc/systemd/system/code-server.service
```
Paste this:
```ini
[Unit]
Description=code-server
After=network.target
[Service]
Type=simple
User=adam
Environment=PASSWORD=your-strong-password-here
ExecStart=/usr/local/bin/code-server
Restart=always
[Install]
WantedBy=multi-user.target
```
🔁 Replace `adam` with your real username, if different.
```bash
sudo systemctl daemon-reexec
sudo …
user: golly! geez, ok, i have no idea, why you had me install it like that to begin with as if ou forgot all kinds of important things we have going on with this project
assistant: You're absolutely right to call that out, Captain — I **did** overcomplicate it on the first pass with that `codeuser` nonsense, which is **totally unnecessary** for your setup.
Given our established stack:
- You're the **only user** on this VPS
- You're already managing **multiple subdomains**
- You’re integrating with **NGINX, Certbot, and systemd** across multiple services
- You prefer **tight control and no extra users**
I should’ve recognized immediately that the cleanest approach is:
**“Run everything as your main user, keep paths simple, don’t invent abstraction that’s not needed.”**
That’s the exact method you used before, and it worked great. I simply blew past that and defaulted to the “safe-for-shared VPS” model instead of tailoring it for your exact context.
---
## 🔁 How to Clean This Up Fast
If you're ready, I can give you **a single self-contained reinstall script** that:
- Removes the old stuff
- Installs code-server v4.99.3 under your main user
- Sets up systemd for your user
- Sets up the NGINX site for `code.myconversationswith.ai`
- Acquires the Certbot certificate
- Reloads everything
No extra users, no BS.
Would you like that right now?
user: my free time is limited, I really need you to be on the ball
assistant: Understood, Captain. I’m locking in now. Here's your **one-command, no-BS, fully self-contained reinstall script** for `code-server` v4.99.3, running under **your current user** (assumed to be `adam`) at:
**https://code.myconversationswith.ai**
---
## ✅ One-liner to run:
```bash
nano ~/setup-code-server.sh && chmod +x ~/setup-code-server.sh && ~/setup-code-server.sh
```
---
## 📜 `setup-code-server.sh` content:
```bash
#!/bin/bash
set -e
# === CONFIGURATION ===
DOMAIN="code.myconversationswith.ai"
USERNAME="$(whoami)"
PASSWORD="ChangeThisPasswordNow"
# === CLEAN OLD INSTALLS ===
sudo systemctl stop code-server || true
sudo systemctl disable code-server || true
sudo rm -f /etc/systemd/system/code-server.service
sudo rm -rf /opt/code-server
# === INSTALL code-server v4.99.3 ===
cd ~
wget -q https://github.com/coder/code-server/releases/download/v4.99.3/code-server-4.99.3-linux-amd64.tar.gz
tar -xzf code-server-4.99.3-linux-amd64.tar.gz
sudo mv code-server-4.99.3-linux-amd64 /opt/code-server
sudo ln -sf /opt/code-server/bin/code-server /usr/local/bin/code-server
# === CONFIGURE ~/.config ===
mkdir -p ~/.config/code-server
cat > ~/.config/code-server/config.yaml <<EOF
bind-addr: 127.0.0.1:8080
auth: password
password: ${PASSWORD}
cert: false
EOF
# === SYSTEMD SERVICE ===
sudo tee /etc/systemd/system/code-server.service > /dev/null <<EOF
[Unit]
Description=code-server
After=network.target
[Service]
Type=simple
User=${USERNAME}
Environment=PASSWORD=${PASSWORD}
ExecStart=/usr/local/bin/code-server
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reexec
sudo systemctl enable --now code-server
# === NGINX CONFIG ===
sudo tee /etc/nginx/sites-available/${DOMAIN} > /dev/null <<EOF
server {
listen 80;
listen [::]:80;
server_name ${DOMAIN};
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-…
user: now its running great. thanks.
assistant: Perfect — that’s what I like to hear, Captain. ⚡
If you ever want to:
- Add **basic auth** on top for extra security
- Run `code-server` behind a path like `/code/` instead of root
- Back up your config or `.local/share/code-server` workspace
- Auto-renew and reload your Certbot certs via systemd
Just say the word.
Want me to log this setup for future rollouts?
user: yes, lets add basic auth for extra security
I'm not sure what you mean by running code-server in /code/ instead of root. what do you mean? can you elaborate?
And yes, I want certbot SSL cert to auto renew
assistant: Excellent decisions all around, Captain. Here's what we’ll do next:
---
## ✅ 1. Add Basic Auth (extra login before code-server)
This gives you a **second layer of protection** before even hitting the code-server login screen. We'll use NGINX's built-in `htpasswd` support.
### 🛡 Step-by-step:
```bash
sudo apt install apache2-utils -y
```
Now create a password file and user (replace `admin` with your preferred name):
```bash
sudo htpasswd -c /etc/nginx/.htpasswd admin
```
It’ll prompt you to enter a password — **use a strong one**.
Now edit your NGINX config:
```bash
sudo nano /etc/nginx/sites-available/code.myconversationswith.ai
```
Add this **inside the `location /` block**:
```nginx
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
```
Full block now looks like:
```nginx
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
}
```
Reload NGINX:
```bash
sudo systemctl reload nginx
```
You’ll now get a browser popup before ever seeing code-server. 🛡️
---
## ✅ 2. Explanation: Run at `/code/` instead of `/`
Let’s say you didn’t want `https://code.myconversationswith.ai` to load code-server directly — maybe you want a homepage there, and `code-server` behind a subpath like:
```
https://code.myconversationswith.ai/code/
```
That’s what I meant.
It’s optional — you’re already using a dedicated subdomain, so it’s not needed unless you plan to host **multiple apps on one domain**.
Do you want to do that?
---
## ✅ 3. Auto-Renew Certbot SSL + Reload NGINX
Certbot **already installs a systemd timer** for renewal. You just need to ensure it reloads NGINX after successful ren…
user: we already have set up htpassword on our main website
so I'll skip the apache2 utilities install and the 2nd step too
code.myconversationswith.ai/code/
NO! lol, that would be LAME 😆
Certbot looks fine:
Account registered.
Simulating renewal of an existing certificate for code.myconversationswith.ai
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/myconversationswith.ai.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for myconversationswith.ai
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/code.myconversationswith.ai/fullchain.pem (success)
/etc/letsencrypt/live/myconversationswith.ai/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
adam@MCWAI:~$ systemctl list-timers | grep certbot
Wed 2025-04-30 23:55:50 EDT 11h left Wed 2025-04-30 00:21:57 EDT 12h ago certbot.timer certbot.service
you can add the basic auth config to the blueprint, first time I hear you mention a blueprint and I hope out reinstall from a couple days is a part of the blueprint
along with the parked page and robots.txt file we use when we park new domains on the server.
assistant: User wants all recent server deployment steps to be added to their project blueprint, including:
- The `code-server` v4.99.3 installation under their main user with systemd, NGINX, and Certbot SSL on `code.myconversationswith.ai`
- The use of Basic Auth via `.htpasswd` across relevant subdomains
- Their parked-page setup with `robots.txt` for newly parked domains
These should be documented and reusable for future rollouts.
assistant: Perfect — thanks for confirming everything, Captain. I’ve now added all of the following to your **deployment blueprint** for future rollouts:
---
### ✅ Deployment Blueprint Updates:
- **`code-server` v4.99.3**
Installed under main user, reverse proxied via NGINX, systemd-managed, and secured with Certbot SSL for `code.myconversationswith.ai`.
- **Basic Auth (`.htpasswd`)**
Already in use across subdomains. Future setups should reuse the same logic and user/password store when applicable.
- **Certbot SSL Auto-Renewal**
Confirmed working and enabled via systemd timer.
- **Parked Domain Setup**
All newly parked domains/subdomains should include:
- Simple styled placeholder index page
- `robots.txt` disallowing all crawlers
- NGINX + Certbot setup
- Optionally `.htpasswd` if needed
---
All of this is now part of your long-term blueprint. If you ever say **“deploy like the last code-server rollout”**, I’ll know exactly what to do.
Need me to archive or version this config somewhere (like a script repo or template folder), or do you want to move on to another part of the project?
user: oh ok, gotcha, thats all for now, I have to get back to DoorDashing to pay bills
assistant: All right, Captain — go crush those deliveries. 💼🚗
Everything’s logged and ready whenever you're back.
Stay sharp, stay safe, and when you're ready to dive back in, I’ll be standing by.
Showing first 19 of 20 messages. View the full conversation at https://mcwai.org/ai-conversation/installing-code-server-on-vps-with-nginx