搭建一个在线翻译网站
编辑介绍
Lingva Translate —谷歌翻译的第三方版,作者原本的目的是防止隐私追踪。可以自建,有语音朗读🤩
—GitHub (https://github.com/thedaviddelta/lingva-translate)
提供的有API 具体参考github
注意
建议搭建在国外服务器,需要服务器能正常访问Google
采用docker方式部署
方式一 docker run
docker run -p 3001:3000 -e site_domain=translate.wxy97.com -e force_default_theme=light -e default_source_lang=auto -e default_target_lang=en thedaviddelta/lingva-translate:latest
方式二 Docker Compose
新建
docker-compose.yaml
文件
version: '3'
services:
lingva:
container_name: lingva
image: thedaviddelta/lingva-translate:latest
restart: unless-stopped
environment:
- site_domain=translate.wxy97.com
- force_default_theme=light
- default_source_lang=auto
- default_target_lang=en
ports:
- 3001:3000
我这里3000端口已经在使用了,我这里映射到3001,域名改成自己的。
docker compose up -d
命令启动
然后修改nginx配置文件反代到3001端口即可;
upstream translate {
server 127.0.0.1:3001;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /usr/local/nginx/conf/ssl/translate.wxy97.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/translate.wxy97.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name translate.wxy97.com;
access_log off;
index index.html index.htm index.php;
root /data/wwwroot/translate.wxy97.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
include /usr/local/nginx/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://translate;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
proxy_pass http://translate;
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
proxy_pass http://translate;
expires 7d;
access_log off;
}
location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
deny all;
}
location /.well-known {
allow all;
}
}
部署在Vercel(没有国外服务器可选择这个)
查看内存占用
docker stats
命令
完成
我搭建好的成品预览: translate.wxy97.com
- 13
- 0
-
分享