usememos / memos

An open source, lightweight note-taking service. Easily capture and share your great thoughts.
https://usememos.com
MIT License
28.86k stars 2.15k forks source link

Base Url Installation Support / 二级目录安装支持 and my partial workaround #2129

Closed sulisu closed 10 months ago

sulisu commented 11 months ago

Is your feature request related to a problem?

No

Describe the solution you'd like

Please add suppport for base url when possible. So Memos can run from a base url such as:

https://www.acme.com/private/memos/

Additional context

mode: prod version: 0.14.3

Run from windows binary directly.

Now ,I managed to make a partial workaround with Caddy2(replace plugin)

Web client works with some little problem, while 3rd party app can not login.

My reverse proxy config for memos

  redir /{Base Url}       /{Base Url}/       301

  route /{Base Url}/* {
    uri strip_prefix /{Base Url}
    replace {
      "/assets/" "/{Base Url}/assets/"
      "/api/" "/{Base Url}/api/"
      "\"assets/" "\"{Base Url}/assets/"
      "\"/auth" "\"/{Base Url}/auth"
      "\"/manifest.json" "\"/{Base Url}/manifest.json"
      "\"/logo.webp" "\"/{Base Url}/logo.webp"
      "o/r" "{Base Url}/o/r"
      "href=\"/\"" "href=\"/{Base Url}\""
      "register(\"/" "register(\"/{Base Url}/"
    }
    reverse_proxy {memos server ip}:{port} {
      header_up X-Script-Name /{Base Url}
      header_up Accept-Encoding identity

    }
  }

URL scheme has changed a lot from 0.14.x, following is a working Caddfile config with replace plugin for 0.19.0. And it works with MoeMemos for Android 0.7.3:

  redir /{Base Url}       /{Base Url}/       301

  route /{BaseURL}/* {
    uri strip_prefix /{BaseURL}
    replace {
# request url https://{hostname:port}/{BaseURL}/
      "href=\"/apple-touch-icon.png" "href=\"/{BaseURL}/apple-touch-icon.png"
      "href=\"/logo.webp" "href=\"/{BaseURL}/logo.webp"
      "href=\"/site.webmanifest" "href=\"/{BaseURL}/site.webmanifest"
      "=\"/assets/" "=\"/{BaseURL}/assets/"
# request url https://{hostname:port}/{BaseURL}/site.webmanifest
      "src\": \"/android-chrome-" "src\": \"/{BaseURL}/android-chrome-"
# request url https://{hostname:port}/{BaseURL}/assets/index-wLOWLptc.js
      "\"/logo.webp\"" "\"/{BaseURL}/logo.webp\""
      "\"/api/v1/" "\"/{BaseURL}/api/v1/"
      "`/api/v1/" "`/{BaseURL}/api/v1/"
      "\"/auth/\"" "\"/{BaseURL}/auth/\""
      "\"/auth/signup\"" "\"/{BaseURL}/auth/signup\""
      "},{path:\"/\",element:jsxRuntimeExports.jsx" "},{path:\"/{BaseURL}/\",element:jsxRuntimeExports.jsx"
      "\",fullName:\"memos.api.v2." "\",fullName:\"{BaseURL}/memos.api.v2."
      "\"/explore\"" "\"/{BaseURL}/explore\""
      "\"assets/" "\"{BaseURL}/assets/"
      "o/r" "{BaseURL}/o/r"
# request url https://{hostname:port}/{BaseURL}/assets/useResponsiveWidth-MAgAVgyT.js
      "window.location.href=\"/auth\"" "window.location.href=\"/{BaseURL}/auth\""
      "home\",path:\"/\"" "home\",path:\"/{BaseURL}/\""
      "\"/timeline\"" "\"/{BaseURL}/timeline\""
      "\"/resources\"" "\"/{BaseURL}/resources\""
      "\"/explore\"" "\"/{BaseURL}/explore\""
      "`/u/${encodeURIComponent" "`/{BaseURL}/u/${encodeURIComponent"
      "\"/inbox\"" "\"/{BaseURL}/inbox\""
      "\"/archived\"" "\"/{BaseURL}/archived\""
      "\"/setting\"" "\"/{BaseURL}/setting\""
      "\"/auth\"" "\"/{BaseURL}/auth\""
      "\"/about\"" "\"/{BaseURL}/about\""
# request https://{hostname:port}/{BaseURL}/assets/SignIn-q4V2JnxN.js
      "fetchCurrentUser(),v(\"/\")" "fetchCurrentUser(),v(\"/{BaseURL}/\")"
# request https://{hostname:port}/{BaseURL}/assets/UserProfile-8qFLOjS-.js
      ",href:`/u/${t==null" ",href:`/{BaseURL}/u/${t==null"
# request https://{hostname:port}/{BaseURL}/assets/Resources-J16PVxLA.js
      "to:`/m/${d.name" "to:`/{BaseURL}/m/${d.name"
    }
    reverse_proxy {serviceIP:port} {
      header_up X-Script-Name /{BaseURL}
      header_up Accept-Encoding identity
    }
  }
dianso commented 11 months ago

nginx 反向代理就行

我就是把50000端口反代到a.com/memos

Issues-translate-bot commented 11 months ago

Issue is not in English. It has been translated automatically.


nginx reverse proxy will do

I just reversed port 50000 to a.com/memos

sulisu commented 11 months ago

nginx 反向代理就行

我就是把50000端口反代到a.com/memos

nginx和memos都是默认配置,不需要特殊配置吗?

因为我看http往返内容,如果不在反向代理上对response内容替换字符串添加baseurl,返回的进一步访问请求都是域名后面直接跟memos自身路径比如/assets,不带baseurl的。因为我在caddy2上配置了过滤,不是baseurl路径下的访问请求全部401。如果不配置替换,在chrome的开发者工具下,是会看到第一个带baseurl的访问之后,后面的访问请求都没有baseurl,而且全部被caddy2返回401拒绝(是caddy2返回的,不是memos返回的)。

您可以试下,如果在nginx下配置了访问策略,只允许hostname:50000/memos路径访问,对hostname:50000/assets这样的访问全部拒绝,是不是还能正常访问。

Issues-translate-bot commented 11 months ago

Issue is not in English. It has been translated automatically.


nginx reverse proxy will do

I just reversed port 50000 to a.com/memos

Both nginx and memos are configured by default, so no special configuration is required?

Because I look at the http round-trip content, if the baseurl is not added to the response content replacement string on the reverse proxy, the further access requests returned are directly followed by the domain name followed by the path of memos itself, such as /assets, without baseurl. Because I have configured filtering on caddy2, not all access requests under the baseurl path are 401. If you do not configure the replacement, under the developer tools of chrome, you will see that after the first access with baseurl, the subsequent access requests do not have baseurl, and all of them are rejected by caddy2 with 401 response (returned by caddy2, not memos) of).

You can try, if the access policy is configured under nginx, only hostname:50000/memos path access is allowed, and all accesses such as hostname:50000/assets are denied, can it still be accessed normally.

dianso commented 11 months ago

晚上我试试吧,我用的倒是没问题,没用docker,直接是二进制运行

Issues-translate-bot commented 11 months ago

Issue is not in English. It has been translated automatically.


I'll try it tonight, it's okay to use it, I don't use docker, just run the binary directly

bfahrenfort commented 10 months ago

Also unable to get memos working in a subdirectory like my-domain.com/memos. memos.my-domain.com works just fine for now, but this requires another DNS record pointing memos.my-domain.com to the IP of my server.

boojack commented 10 months ago

memos.my-domain.com works just fine for now

I recommend this as standard usage.

Issues-translate-bot commented 9 months ago

Issue is not in English. It has been translated automatically.


@boojack portainer does not have this problem and can work normally in sub-paths. You can refer to their solutions.