Stable Diffusion (Web UI) Debian 自托管

使用 Nginx 反代 AUTOMATIC1111 的 Stable Diffusion Web UI

环境

  • Debian 11
    • Python 3.9.2

步骤

准备运行环境

wget git python3-venv libglib2.0-0 libsm6 libxrender1 libxext6

Web UI 无法运行在 root 用户环境下,如果平时使用 root 用户,需要新建普通用户

adduser [username]
# 按提示配置一些信息
usermod -a -G sudo [username] # 加入 sudo 用户组

新建完毕后切换到该用户

su - [username]

安装并配置 Stable Diffusion Web UI

执行指令安装 Web UI

bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh)

安装完毕后关闭启动的 Web UI

编辑项目根目录下的 webui-user.sh,按需修改相应配置(下图修改了默认监听端口),关于运行参数可以查看 https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings

配置系统服务

在 /etc/systemd/system 下新建文件 stable-diffusion.service,写入以下内容

[Unit]
Description=stable diffusion web ui.

[Service]
User=[user]
Group=[user]
WorkingDirectory=/path/to/stable-diffusion-webui
ExecStart=/bin/bash /path/to/stable-diffusion-webui/webui.sh

[Install]
WantedBy=multi-user.target

启动服务并设置开机启动

systemctl enable stable-diffusion.service --now

配置 Nginx

在 /etc/nginx/sites-avaliable 下新建配置文件 stable-diffusion.conf,写入以下内容

server {
        listen [port];
        server_name [server name];

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://127.0.0.1:[web ui listen port];
        }
}

新建软链接

ln -s /etc/nginx/sites-available/stable-diffution.conf /etc/nginx/sites-enabled/

重载 Nginx 配置文件

nginx -t
nginx -s reload

效果

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据