Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KB custom URL does not work #2627

Closed
MrGeneration opened this issue Jun 26, 2019 · 9 comments
Closed

KB custom URL does not work #2627

MrGeneration opened this issue Jun 26, 2019 · 9 comments
Assignees

Comments

@MrGeneration
Copy link
Member

MrGeneration commented Jun 26, 2019

Infos:

  • Zammad-Version: 3.0 stable
  • Web-Server: Apache 2.4 (not tested with nginx because of time reasons, I expect the behavior to be exact the same)
  • ES-Version: 5.6, but any
  • database: any
  • Browsers: Firefox and Chrome (current)

expected behavior

  • When entering a custom subfolder and submitting that as custom URL, the rewrite rules needed (and supplied) are correct and working
  • when entering a custom subdomain and submitting that as custom URL, the rewrite rules needed (and supplied) are correct and working

actual behavior

  • When entering a custom subfolder and submitting that as custom URL, the rewrite rules needed (and supplied) are not working in that context
  • when entering a custom subdomain and submitting that as custom URL, the rewrite rules needed (and supplied) are not working in that context

Both rewrite rule types provided, will hardly redirect the Browser to another URL which fails, rails will not find that redirected URLs for.. reasons.

Solution:

Sub-Directory

Easiest solution for subfolders is to use a proxy (tested):

Apache

ProxyPass /support http://127.0.0.1:3000/help "retry=1 acque=3000 timeout=600 keepalive=On"

nginx
nginx is currently untested (as of 26th June 2pm)

The above samples always need to live above the location / Proxypass / - otherwise it won't work (/ will snack it away).

Subdomain

Easiest solution for subfolders is to use a proxy (tested):

Apache

    SSLProxyEngine On
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass /assets https://domain.tld/assets  "retry=1 acque=3000 timeout=600 keepalive=On"
    ProxyPass / http://127.0.0.1:3000/help/ "retry=1 acque=3000 timeout=600 keepalive=On"

If you (why ever you wanna do that) want to use a HTTP vHost, you need to disable security stuff, not recommendet:

SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

nginx
nginx is currently untested (as of 26th June 2pm)

@totoCZ
Copy link

totoCZ commented Oct 26, 2019

If you're lucky to have nginx compiled with sub_filter (it's that way in docker)

    location /api/ {
        sub_filter '/help/en-us' '';
        sub_filter_once off;
        sub_filter_types application/json;
        proxy_set_header X-ORIGINAL-URL $request_uri;
        proxy_set_header Host $http_host;
        proxy_set_header CLIENT_IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 300;
        proxy_pass http://zammad/api/;
    }

    location / {
        proxy_redirect /help/en-us /;
        sub_filter '/help/en-us' '';
        sub_filter_once off;
        proxy_set_header X-ORIGINAL-URL $request_uri;
        proxy_set_header Host $http_host;
        proxy_set_header CLIENT_IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 300;
       	proxy_pass http://zammad/help/en-us/;
    }

This has the advantage of removing en-us as well. I don't need it for a single language KB.
Otherwise, it should be pretty simple to change.

@MrGeneration MrGeneration assigned MrGeneration and unassigned mantas Dec 10, 2019
@thorsteneckel thorsteneckel added this to the 3.2.1 milestone Dec 10, 2019
@MrGeneration MrGeneration modified the milestones: 3.2.1, 3.3.1 Feb 25, 2020
@MrGeneration
Copy link
Member Author

So I finally was able to roll this one up again.
Most of the things are working out of the box by now, mantas has been fixing that proberbly indirectly with other issues. 💪

Especially the subdomain examples ensure to not have a /help being displayed, as I personally think that'd be doubled and looks ugly.


So - the following suggestions are working without changes and thus shall stay the same:

Apache subdirectory
Example below uses /support as custom URL.

# Add following lines to <VirtualHost> directive
RewriteEngine On
RewriteRule ^/support(.*) /help$1 [PT]

# Add following lines to <VirtualHost> directive, before ProxyPass
SetEnvIf Request_URI "(.*)" ORIGINAL_URL=$1
RequestHeader add X-ORIGINAL-URL %{ORIGINAL_URL}e

nginx subdirectory
Sames goes for nginx, works like a charm if you're careful about what the comments say :)

# Add following lines to "server" directive
rewrite ^/support(.*)$ /help$1 last;

# Add following line to "Location /" directive, before other proxy_set_header
proxy_set_header X-ORIGINAL-URL $request_uri;

required changes

@mantas please have a look at the following directives and add them to the knowledge base suggestion for code:

Apache subdomain

  # Add following lines to <VirtualHost> directive
  # Technically can be the same VirtualHost as your main Zammad if needed
    RewriteEngine On
    RewriteCond %{HTTP_HOST} DOMAIN.TLD
    RewriteRule (assets|api)/(.*) /$1/$2 [PT]
    RewriteCond %{HTTP_HOST} DOMAIN.TLD
    RewriteRule ^/help(.*) /$1 [R=302]

  # Add following lines to <VirtualHost> directive, before ProxyPass
    SetEnvIf Request_URI "(.*)" ORIGINAL_URL=$1
    RequestHeader add X-ORIGINAL-URL %{ORIGINAL_URL}e
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy 127.0.0.1:3000>
      Require local
    </Proxy>

    ProxyPass /assets !
    ProxyPass /favicon.ico !
    ProxyPass /robots.txt !
    ProxyPass / http://127.0.0.1:3000/help/ "retry=1 acque=3000 timeout=600 keepalive=On"

nginx subdomain
In my tests I've been struggling a lot here. I came to the conclusion you should use your own server directive for this configuration.

    # Please add the following in it's **own** server directive!
    # Gladly use the same .conf file. Pasting the following into the same server directive
    # like your Zammad will **not work**.
    root /opt/zammad/public;
    location ~ ^/(assets/|robots.txt|humans.txt|favicon.ico) {
      expires max;
    }

    if ($host = DOMAIN.TLD ) {
     rewrite ^/(api|assets)/(.*)$ /$1/$2 last;
     rewrite ^(.*)$ /$1 last;
   }

    location / {
      proxy_set_header X-ORIGINAL-URL $request_uri;
      proxy_set_header Host $http_host;
      proxy_set_header CLIENT_IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_read_timeout 180;
      proxy_pass http://zammad-railsserver/help/;

      gzip on;
      gzip_types text/plain text/xml text/css image/svg+xml application/javascript application/x-javascript application/json application/xml;
      gzip_proxied any;
    }

Alternative (apache subdirectory)

The following configuration style does work as well, if you want to. This is just a hint in case some one would prefer proxying over rewriting for apache subdirectories:

# Add following lines to <VirtualHost> directive, before ProxyPass
SetEnvIf Request_URI "(.*)" ORIGINAL_URL=$1
RequestHeader add X-ORIGINAL-URL %{ORIGINAL_URL}e
ProxyPass /support http://127.0.0.1:3000/help "retry=1 acque=3000 timeout=600 keepalive=On"

Note that the above is not officially supported by Zammad and might change in behaviour as we do not test for this use case.

@MrGeneration MrGeneration assigned mantas and unassigned MrGeneration Mar 17, 2020
@thorsteneckel thorsteneckel modified the milestones: 3.3.1, 3.4.0 Mar 17, 2020
@mantas
Copy link
Collaborator

mantas commented Mar 18, 2020

@MrGeneration DOMAIN.TLD is what comes from the input field. Correct?

There's a third theoretical case that it may be custom (sub)domain + path. E.g. zammad sits at support.example.org, but KB is at another.example.org/kb

@MrGeneration
Copy link
Member Author

Yes, DOMAIN.TLD is to be placeholdered wijth the input fields value. Sorry for not being specific on that. :D

Good hint about the third use case. Shall I have a look on rules for that as well? I mean, is that a use case the code currently supports and can differ? If so I'll do my homework! :D

@mantas
Copy link
Collaborator

mantas commented Mar 18, 2020

Yes, existing code does (or should?) support it.

Current server config snippet look like this to account for that:

At first sight, your example seem to have hardcoded value that works only if no path was entered. Current implementation takes custom path into account following way:

Apache

RewriteRule #{path}(.*) /help$1 [PT]

https://github.com/zammad/zammad/blob/develop/lib/knowledge_base/server_snippet_apache.rb

Nginx
rewrite ^#{path}(.*)$ /help$1 last;

https://github.com/zammad/zammad/blob/develop/lib/knowledge_base/server_snippet_nginx.rb

@MrGeneration
Copy link
Member Author

I've had another look onto the combination of custom FQDN together with a subfolder structure.
When entering my.domain.tld/support Zammad does not correctly recognize it, it just recognizes the subdirectory.

image

So I'm not sure if the code can really carry this.


Expecting to use "domain.tld" with subdirectory /support.
So if you wanna use FQDN + subdirectory you'd need:

Apache2

  # Add following lines to <VirtualHost> directive
  # Technically can be the same VirtualHost as your main Zammad if needed
    RewriteEngine On
    RewriteCond %{HTTP_HOST} DOMAIN.TLD
    RewriteRule (assets|api)/(.*) /$1/$2 [PT]
    RewriteCond %{HTTP_HOST} DOMAIN.TLD
    RewriteRule ^/support(.*) /help$1 [R=302]

  # Add following lines to <VirtualHost> directive, before ProxyPass
    SetEnvIf Request_URI "(.*)" ORIGINAL_URL=$1
    RequestHeader add X-ORIGINAL-URL %{ORIGINAL_URL}e
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy 127.0.0.1:3000>
      Require local
    </Proxy>

    ProxyPass /assets !
    ProxyPass /favicon.ico !
    ProxyPass /robots.txt !
    ProxyPass /help http://127.0.0.1:3000/help "retry=1 acque=3000 timeout=600 keepalive=On"

It didn't seem to work with nginx.
Zammad failed to recognize the correct URL or I was choosiung wrong directives.

@thorsteneckel
Copy link
Contributor

Hey guys! How is this issue coming along? We're planing a new release of Zammad and this one is assigned to the next release (for quite a while).

@MrGeneration
Copy link
Member Author

MrGeneration commented Apr 20, 2020

Nothing new to add from my end, my last two three comments are (for me) the as is.

@MrGeneration
Copy link
Member Author

I double checked above constellations and have taken the following use cases in consideration (and verified them to be working):

  • knowledgebase without any changes ( /help )
  • knowledgebase with custom alias ( /support as example )
  • knowledgebase with custom domain ( help.example.com )
  • knowledgebase with custom domain and alias ( help.example.com/support )

As of today I can no longer reproduce this on my test environments.
I'm absolutely puzzled and ashamed. ^^"

I'll therefor close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants