Nginx 反向代理
您可能希望使用您的 nginx 服务器作为反向代理来运行 gotify。
在域名根目录下
以下是一个示例配置文件,适用于在端口 1245 上运行您的 Gotify 实例的情况。
upstream gotify {
# Set the port to the one you are using in gotify
server 127.0.0.1:1245;
}
server {
listen 80;
# Here goes your domain / subdomain
server_name push.example.com;
location / {
# We set up the reverse proxy
proxy_pass http://gotify;
proxy_http_version 1.1;
# Ensuring it can use websockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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 http;
proxy_redirect http:// $scheme://;
# The proxy must preserve the host because gotify verifies the host with the origin
# for WebSocket connections
proxy_set_header Host $http_host;
# These sets the timeout so that the websocket can stay alive
proxy_connect_timeout 1m;
proxy_send_timeout 1m;
proxy_read_timeout 1m;
}
}若要通过 Nginx 启用 HTTPS,请保持 Gotify 设置‘GOTIFY_SERVER_SSL_ENABLED=false‘,并像处理其他网站一样依赖 Nginx 来加密流量。
在子路径下
以下是上述示例配置的等效版本,但运行在子路径下
upstream gotify {
# Set the port to the one you are using in gotify
server 192.168.178.34:8080;
}
server {
listen 80;
server_name localhost;
location /gotify/ {
proxy_pass http://gotify;
rewrite ^/gotify(/.*) $1 break;
proxy_http_version 1.1;
# Ensuring it can use websockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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 http;
proxy_redirect http:// $scheme://;
# The proxy must preserve the host because gotify verifies the host with the origin
# for WebSocket connections
proxy_set_header Host $http_host;
proxy_connect_timeout 1m;
proxy_send_timeout 1m;
proxy_read_timeout 1m;
}
}作者:Jeebiz 创建时间:2025-12-04 10:41
最后编辑:Jeebiz 更新时间:2025-12-04 11:29
最后编辑:Jeebiz 更新时间:2025-12-04 11:29