Spaces:
Running
Running
Jarvis Bot commited on
Commit ·
cb8a063
1
Parent(s): 7f46897
Add nginx reverse proxy for multi-service routing
Browse files- nginx listens on :7860 as main entry point
- / → code-server on :8443 (password protected)
- /files/ → dufs on :5000 (public, no auth required)
- Installs nginx and dufs in Dockerfile
- All services start from start_server.sh
- Dockerfile +24 -35
- nginx.conf +79 -0
- start_server.sh +30 -3
Dockerfile
CHANGED
|
@@ -4,7 +4,7 @@ FROM python:3.9
|
|
| 4 |
# Set environment variables
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
|
| 7 |
-
# Install
|
| 8 |
RUN apt-get update && \
|
| 9 |
apt-get install -y \
|
| 10 |
curl \
|
|
@@ -20,62 +20,51 @@ RUN apt-get update && \
|
|
| 20 |
nmap \
|
| 21 |
ca-certificates \
|
| 22 |
zsh \
|
| 23 |
-
rclone
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Install Node.js (LTS version)
|
| 27 |
-
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x |
|
| 28 |
-
apt-get install -y nodejs
|
| 29 |
-
|
| 30 |
-
RUN npm install -g pnpm@8.3.1 pm2 ts-node
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Install code-server
|
| 34 |
-
RUN curl -fsSL https://code-server.dev/install.sh | sh -
|
| 35 |
-
|
| 36 |
|
| 37 |
# Create a user to run code-server
|
| 38 |
RUN useradd -m -s /bin/zsh coder && \
|
| 39 |
echo 'coder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
| 40 |
|
| 41 |
# Create code-server configuration directory
|
| 42 |
-
RUN mkdir -p /home/coder/.local/share/code-server/User
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# Add settings.json to enable dark mode
|
| 46 |
-
RUN echo '{ \
|
| 47 |
"workbench.colorTheme": "Default Dark Modern", \
|
| 48 |
"telemetry.enableTelemetry": true, \
|
| 49 |
"telemetry.enableCrashReporter": true \
|
| 50 |
-
}' > /home/coder/.local/share/code-server/User/settings.json
|
| 51 |
-
|
| 52 |
-
# Change ownership of the configuration directory
|
| 53 |
-
RUN chown -R coder:coder /home/coder/.local/share/code-server
|
| 54 |
|
| 55 |
# Install Python extension for code-server
|
| 56 |
RUN sudo -u coder code-server --install-extension ms-python.python
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
PATH=/home/coder/.local/bin:$PATH
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
WORKDIR /home/coder
|
| 68 |
|
| 69 |
-
# 创建rclone配置文件
|
| 70 |
-
RUN rclone config -h
|
| 71 |
-
|
| 72 |
-
# Start code-server with authentication
|
| 73 |
-
# CMD ["sh", "-c", "code-server --bind-addr 0.0.0.0:7860"]
|
| 74 |
-
|
| 75 |
-
CMD ["sh", "-c", "/home/coder/start_server.sh"]
|
| 76 |
-
# ENTRYPOINT ["/home/coder/start_server.sh"]
|
| 77 |
-
|
| 78 |
-
# Expose the default code-server port
|
| 79 |
EXPOSE 7860
|
| 80 |
|
| 81 |
-
|
|
|
|
| 4 |
# Set environment variables
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
|
| 7 |
+
# Install system packages
|
| 8 |
RUN apt-get update && \
|
| 9 |
apt-get install -y \
|
| 10 |
curl \
|
|
|
|
| 20 |
nmap \
|
| 21 |
ca-certificates \
|
| 22 |
zsh \
|
| 23 |
+
rclone \
|
| 24 |
+
nginx \
|
| 25 |
+
wget && \
|
| 26 |
+
rm -rf /var/lib/apt/lists/*
|
| 27 |
|
| 28 |
# Install Node.js (LTS version)
|
| 29 |
+
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
|
| 30 |
+
apt-get install -y nodejs && \
|
| 31 |
+
npm install -g pnpm@8.3.1 pm2 ts-node
|
|
|
|
| 32 |
|
| 33 |
+
# Install dufs (latest binary)
|
| 34 |
+
RUN wget -qO /usr/local/bin/dufs https://github.com/sigoden/dufs/releases/latest/download/dufs-x86_64-unknown-linux-musl && \
|
| 35 |
+
chmod +x /usr/local/bin/dufs
|
| 36 |
|
| 37 |
# Install code-server
|
| 38 |
+
RUN curl -fsSL https://code-server.dev/install.sh | sh -
|
|
|
|
| 39 |
|
| 40 |
# Create a user to run code-server
|
| 41 |
RUN useradd -m -s /bin/zsh coder && \
|
| 42 |
echo 'coder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
| 43 |
|
| 44 |
# Create code-server configuration directory
|
| 45 |
+
RUN mkdir -p /home/coder/.local/share/code-server/User && \
|
| 46 |
+
chmod -R 777 /home/coder && \
|
| 47 |
+
echo '{ \
|
|
|
|
|
|
|
| 48 |
"workbench.colorTheme": "Default Dark Modern", \
|
| 49 |
"telemetry.enableTelemetry": true, \
|
| 50 |
"telemetry.enableCrashReporter": true \
|
| 51 |
+
}' > /home/coder/.local/share/code-server/User/settings.json && \
|
| 52 |
+
chown -R coder:coder /home/coder/.local/share/code-server
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Install Python extension for code-server
|
| 55 |
RUN sudo -u coder code-server --install-extension ms-python.python
|
| 56 |
|
| 57 |
+
# Copy config files
|
| 58 |
+
COPY --chown=coder:coder start_server.sh /home/coder/
|
| 59 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 60 |
|
| 61 |
+
RUN chmod +x /home/coder/start_server.sh
|
|
|
|
| 62 |
|
| 63 |
+
ENV HOME=/home/coder \
|
| 64 |
+
PATH=/home/coder/.local/bin:$PATH
|
| 65 |
|
| 66 |
WORKDIR /home/coder
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
EXPOSE 7860
|
| 69 |
|
| 70 |
+
CMD ["sh", "-c", "/home/coder/start_server.sh"]
|
nginx.conf
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
worker_processes 1;
|
| 2 |
+
|
| 3 |
+
events {
|
| 4 |
+
worker_connections 1024;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
http {
|
| 8 |
+
include /etc/nginx/mime.types;
|
| 9 |
+
default_type application/octet-stream;
|
| 10 |
+
|
| 11 |
+
sendfile on;
|
| 12 |
+
keepalive_timeout 65;
|
| 13 |
+
|
| 14 |
+
server {
|
| 15 |
+
listen 7860;
|
| 16 |
+
server_name _;
|
| 17 |
+
|
| 18 |
+
# -----------------------------
|
| 19 |
+
# code-server (主入口,需要密码)
|
| 20 |
+
# -----------------------------
|
| 21 |
+
location / {
|
| 22 |
+
proxy_pass http://127.0.0.1:8443;
|
| 23 |
+
proxy_http_version 1.1;
|
| 24 |
+
|
| 25 |
+
# WebSocket support (code-server 编辑器需要)
|
| 26 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 27 |
+
proxy_set_header Connection "upgrade";
|
| 28 |
+
|
| 29 |
+
proxy_set_header Host $host;
|
| 30 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 31 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 32 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 33 |
+
|
| 34 |
+
# 长连接超时
|
| 35 |
+
proxy_read_timeout 86400s;
|
| 36 |
+
proxy_send_timeout 86400s;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# -----------------------------
|
| 40 |
+
# dufs 文件服务 (公开,无需登录)
|
| 41 |
+
# -----------------------------
|
| 42 |
+
location /files/ {
|
| 43 |
+
proxy_pass http://127.0.0.1:5000/;
|
| 44 |
+
proxy_http_version 1.1;
|
| 45 |
+
|
| 46 |
+
proxy_set_header Host $host;
|
| 47 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 48 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 49 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 50 |
+
|
| 51 |
+
# CORS 支持
|
| 52 |
+
add_header Access-Control-Allow-Origin *;
|
| 53 |
+
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS, PROPFIND, MKCOL, COPY, MOVE';
|
| 54 |
+
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Depth';
|
| 55 |
+
add_header Access-Control-Max-Age 86400;
|
| 56 |
+
|
| 57 |
+
# dufs WebDAV 需要
|
| 58 |
+
proxy_set_header X-Forwarded-Prefix /files;
|
| 59 |
+
|
| 60 |
+
# OPTIONS 预检请求直接返回
|
| 61 |
+
if ($request_method = OPTIONS) {
|
| 62 |
+
add_header Access-Control-Allow-Origin *;
|
| 63 |
+
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS, PROPFIND, MKCOL, COPY, MOVE';
|
| 64 |
+
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Depth';
|
| 65 |
+
add_header Access-Control-Max-Age 86400;
|
| 66 |
+
add_header Content-Length 0;
|
| 67 |
+
add_header Content-Type text/plain;
|
| 68 |
+
return 204;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
# -----------------------------
|
| 73 |
+
# 旧的 absproxy 路径,重定向到新路径
|
| 74 |
+
# -----------------------------
|
| 75 |
+
location /absproxy/5000/ {
|
| 76 |
+
return 301 /files/;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
}
|
start_server.sh
CHANGED
|
@@ -1,7 +1,34 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
|
| 3 |
-
|
| 4 |
-
echo "$RCLONE_CONF" > ~/.config/rclone/rclone.conf
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
|
| 3 |
+
set -e
|
|
|
|
| 4 |
|
| 5 |
+
echo "====================== Writing rclone config ========================"
|
| 6 |
+
if [ -n "$RCLONE_CONF" ]; then
|
| 7 |
+
mkdir -p ~/.config/rclone
|
| 8 |
+
echo "$RCLONE_CONF" > ~/.config/rclone/rclone.conf
|
| 9 |
+
fi
|
| 10 |
|
| 11 |
+
echo "====================== Starting dufs (port 5000) ========================"
|
| 12 |
+
mkdir -p /data/files
|
| 13 |
+
/usr/local/bin/dufs /data/files \
|
| 14 |
+
--allow-upload \
|
| 15 |
+
--allow-delete \
|
| 16 |
+
--allow-search \
|
| 17 |
+
--allow-archive \
|
| 18 |
+
--enable-cors \
|
| 19 |
+
--port 5000 \
|
| 20 |
+
--bind 127.0.0.1 &
|
| 21 |
+
|
| 22 |
+
sleep 1
|
| 23 |
+
|
| 24 |
+
echo "====================== Starting code-server (port 8443) ========================"
|
| 25 |
+
sudo -u coder code-server \
|
| 26 |
+
--bind-addr 127.0.0.1:8443 &
|
| 27 |
+
|
| 28 |
+
sleep 2
|
| 29 |
+
|
| 30 |
+
echo "====================== Starting nginx (port 7860) ========================"
|
| 31 |
+
# Remove default nginx site configs
|
| 32 |
+
rm -f /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/* /etc/nginx/conf.d/default.conf 2>/dev/null || true
|
| 33 |
+
|
| 34 |
+
nginx -g "daemon off;"
|