使用 nginx 在子目录上运行 etherpad-lite

Posted

技术标签:

【中文标题】使用 nginx 在子目录上运行 etherpad-lite【英文标题】:Running etherpad-lite on subdirectory with nginx 【发布时间】:2016-06-20 00:03:06 【问题描述】:

我在我的服务器上运行 etherpad-lite 1.5.7。在http:\\myserver:9001 下可以访问它,但我想在https:\\myserver\pad 下访问它。

我是这样配置nginx

location /pad 
    rewrite /pad/(.*) /$1 break;
    rewrite ^/pad$ /pad/ permanent;
    proxy_pass http://localhost:9001/;
    proxy_pass_header Server;
    proxy_redirect / /pad/;
    proxy_set_header Host $host;
    proxy_buffering off;


location /pad/socket.io 
    rewrite /pad/socket.io/(.*) /socket.io/$1 break;
    proxy_pass http://localhost:9001/;
    proxy_redirect / /pad/;
    proxy_set_header Host $host;
    proxy_buffering off;
    proxy_set_header X‐Real‐IP $remote_addr; # http://wiki.nginx.org/HttpProxyModule
    proxy_set_header X‐Forwarded‐For $remote_addr; # EP logs to show the actual remote I
    proxy_set_header Host $host; # pass the host header
    proxy_http_version 1.1; # recommended with keepalive connections
    # WebSocket proxying ‐ from http://nginx.org/en/docs/http/websocket.html
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
 

location /static 
    rewrite /static/(.*) /static/$1 break;
    proxy_pass http://localhost:9001/;
    proxy_set_header Host $host;
    proxy_buffering off;

但是当打开一个垫子时,我在日志文件中得到以下错误

^[[33m[2016-03-06 13:05:15.308] [WARN] client - ^[[39mUncaught ReferenceError: io is not defined --  errorId: 'BCdMZzVXqx5Df5TwGUz5',
msg: 'Uncaught ReferenceError: io is not defined',
url: 'https://myserver/pad/p/Testpad',
linenumber: 232,
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36' 

火狐说

https://myserver/pad/socket.io/socket.io.js Failed to load resource: the server responded with a status of 502 (Bad Gateway)
pad.js?callback=require.define:232 Uncaught ReferenceError: io is not defined

管理面板无法显示设置文件或插件。

感谢您的帮助!

【问题讨论】:

【参考方案1】:

我刚刚安装了以下设备,所以它还没有经过测试。这假设您在 https 下运行 Etherpad-lite 并使用 nginx 反向代理到 localhost。

location /pad/ 
    proxy_pass http://localhost:9001;
    rewrite /pad(/.*)$ $1 break;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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 https;
    proxy_http_version      1.1;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffers           32 4k;
    proxy_intercept_errors  on;

location /pad  rewrite /pad /pad/ permanent; 
location /static/  include /etc/nginx/proxy_conf; proxy_pass http://localhost:9001/static/ ;

【讨论】:

以上是关于使用 nginx 在子目录上运行 etherpad-lite的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Sandstorm 上安装 Etherpad Lite 插件?

Etherpad:setHTML API 响应成功,但更新后的 html 在 etherpad 上不可见

Etherpad-lite 有序列表格式化

不断重新连接到 websocket / 会话 ID 未知 / Etherpad

查看最近编辑的 etherpad

etherpad-lite 权限被拒绝,打开 './SESSIONKEY.txt'