nginx 代理

2025-09-25
-
-

配置 Nginx 代理和 HTTPS。这里的作系统是 Ubuntu 18.04。

  1. 下载 Nginx 并删除 Apache2

sudo apt-get install nginx
sudo apt-get remove apache2

2. 创建配置文件

cd /etc/nginx/conf.d
vim default.conf

3. 使用如下所示的上下文填充文件,部分设置显示更改。然后,您可以使用 HTTPS 强制和代理享受您的网络。

# This part configures, where your Trilium server is running
upstream trilium {
  zone trilium 64k;
  server 127.0.0.1:8080; # change it to a different hostname and port if non-default is used
  keepalive 2;
}

# This part is for proxy and HTTPS configure
server {
    listen 443 ssl;
    server_name trilium.example.net; #change trilium.example.net to your domain without HTTPS or HTTP.
    ssl_certificate /etc/ssl/note/example.crt; #change /etc/ssl/note/example.crt to your path of crt file.
    ssl_certificate_key /etc/ssl/note/example.net.key; #change /etc/ssl/note/example.net.key to your path of key file.
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log; #check the path of access.log, if it doesn't fit your file, change it

    location / {
        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";
        proxy_pass http://trilium;
        proxy_read_timeout 90;
    }
}

# This part is for HTTPS forced
server {
    listen 80;
    server_name trilium.example.net; # change to your domain
    return 301 https://$server_name$request_uri;
}

4. 或者,如果您想在不同的路径下为实例提供服务(例如,如果要为多个实例提供服务,则很有用),请按如下方式更新位置块:

  • 使用您想要的路径更新位置(确保不要留下尾随斜杠“/”,如果您的结尾也不是斜杠)proxy_pass

  • 添加具有相同路径的指令:这允许您同时在多个实例上保持登录状态。proxy_cookie_path

    location /trilium/instance-one {
        rewrite /trilium/instance-one/(.*) /$1  break;
        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";
        proxy_pass http://trilium;
        proxy_cookie_path / /trilium/instance-one
        proxy_read_timeout 90;
    }

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

黄金_shmaur
不积跬步,无以至千里;不积小流,无以成江海
目录关闭