用 OneIndex 做了一个图床,基于 Docker 与 Nginx 反代

https://one.appinn.com/

呃,有时候不方便传 gif 在论坛,或者网站,主要是…磁盘空间不足。然后就尝试用普遍流传的 OneIndex 做了一个图床。

https://github.com/donwa/oneindex

踩坑实录,由于 VPS 被删,之前数据丢了,重建后顺便记录一下安装过程:

首先,你需要在 VPS 里安装 docker,可以参考下面这个教程:

安装并配置 OneIndex

目录结构

只需要创建 config 文件夹(文件夹内文件会自动创建)即可将配置持久化,重启 Docker 之类的都不怕数据丢失。

.
├── config
│   ├── base.php
│   └── token.php
└── docker-compose.yml

Oneindex 的 docker-compose.yml 文件内容

注意自行修改路径部分(/root/oneindex/config)为你的 config 所在。

oneindex:
    image:  setzero/oneindex
    ports:
        - 8080:80
    volumes:
        - /root/oneindex/config:/var/www/html/config
    environment:
        - REFRESH_TOKEN='0 * * * *'
        - REFRESH_CACHE='*/10 * * * *'

运行 Oneindex

docker-compose up -d

之后,即可用 IP:8080 访问并设置 Oneindex。

安装并配置 Nginx 反代

由于机器有其他容器在运行,所以有一个单独的 Nginx 专门负责整台机器的所有网页服务,只需要简单的配置下就行了,也顺便记录下。

目录结构

.
├── conf.d
│   └── one.conf
├── docker-compose.yml
├── nginx.conf
├── ssl
│   ├── appinn.crt
│   ├── appinn.csr
│   └── appinn.key
└── www
    └── www

说明下这个目录,conf.d 为 Nginx 配置文件夹,以后想加网站就直接向里面添加,然后重启 Nginx 即可。nginx.conf 为默认即可,但注意要包括 conf.d 目录,ssl 为安全证书文件夹,www 为网页文件目录,此例中无用,可不要。

一个 nginx.conf 例子

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log off;
    include /etc/nginx/conf.d/*.conf;
}

one.conf 例子

server {
    listen 443 ssl http2;
    server_name one.appinn.com;

    ssl_certificate      /etc/nginx/ssl/appinn2019.crt;
    ssl_certificate_key  /etc/nginx/ssl/appinn2019.key;

    location / {
        proxy_pass http://IP:8080;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

docker-compose.yml 内容

nginx:
    image: nginx:stable
    ports:
        - '443:443'
    volumes:
        - ./conf.d:/etc/nginx/conf.d
        - ./nginx.conf:/etc/nginx/nginx.conf
        - ./ssl:/etc/nginx/ssl
        - ./www/www:/var/www
    restart: always

运行:docker-compose up -d

Docker 容器内的 Nginx 重启方法:

修改配置文件后,需要重启 Nginx,容器内可使用下面的命令,但注意修改了 nginx.conf 需要重建容器:

docker exec nginx_nginx_1 nginx -s reload

其中 nginx_nginx_1 为容器名,可以使用 docker ps 命令看到。

碰到文件可使用 docker logs nginx_nginx_1 来查看日志。

效果

最终,就是这个效果: https://one.appinn.com

1 个赞

爱了,爱了

@Qingwa 实测,第五代iPad无法上传…
又拿win7电脑做了测试:无法返回链接…

更新了一下,加了配置方法。网络上的资料很散、很累…