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

Configuration for Piwik behind nginx reverse proxy with path rewrite #12011

Merged
merged 1 commit into from Nov 19, 2017

Conversation

Projects
None yet
4 participants
@user121216
Contributor

user121216 commented Sep 7, 2017

If you're using Piwik behind a reverse proxy with a different path like "rewrite ^/piwik/(.*)$ /$1 break;" (nginx.conf), you can provide a header "proxy_set_header X-Forwarded-Uri /piwik;". If you're enabling the config "proxy_uri_header = 1", the header will be considered to the current script name.

It's necessary, because the redirect after login and links e.g. the logo are not working correctly without.

See question at https://stackoverflow.com/q/46080031/5453237

user121216 user121216
If you're using Piwik behind a reverse proxy with a different path li…
…ke "rewrite ^/piwik/(.*)$ /$1 break;" (nginx.conf), you can provide a header "proxy_set_header X-Forwarded-Uri /piwik;" which will be considered to the current script name.

It's necessary, because the redirect after login and links e.g. the logo are not working correctly without.

@mattab mattab added this to the 3.2.0 milestone Sep 14, 2017

@mattab

This comment has been minimized.

Member

mattab commented Sep 14, 2017

Thanks for the PR @user121216 👍 This issue is likely experienced by many users and would be a welcome solution!

Feedback:

  • Could you check in #6644 whether this is directly related and the same issue? EDIT: also for Apache in #11765

  • we would like to update the Proxy FAQ to explain this setting, here is a first proposal (if you have any feedback?):

If you're using Piwik behind a reverse proxy with a different path such as rewrite ^/piwik/(.*)$ /$1 break; (in nginx.conf), you would need to:

  1. configure the web server to provide a header: proxy_set_header X-Forwarded-Uri /piwik;.
  2. in Piwik config/config.ini.php, add proxy_uri_header = 1 below the [General] section, so that Piwik will use the X-Forwarded-Uri header.
@ToBeReplaced

This comment has been minimized.

ToBeReplaced commented Sep 15, 2017

I wonder if using an HTTP header is a better choice than allowing for a uri_prefix variable directly in the global.php.ini. If there is no case where we want to dynamically change the URI prefix, then we do not need to send it with every request to Piwik. I don't know all of the ways in which Piwik is used though, so maybe that's a feature?

@user121216 what influenced your decision to use an HTTP header?

@user121216

This comment has been minimized.

Contributor

user121216 commented Sep 15, 2017

@ToBeReplaced My decision was inspired by the proxy_host_headers variable and the docker environment. I have 2 docker containers (Nginx proxy and Apache with Piwik). The Piwik container is a standalone solution and the rewrite rule is from the Nginx proxy, so I wanted to keep the reason and the config together in one file (nginx.conf). Another solution could be also to run the Piwik instance under the right directory on the Apache container (/piwik), but this is not a smart way for me.

@mattab You're right. These issues are similar. Next time I have to search better :)

@ToBeReplaced

This comment has been minimized.

ToBeReplaced commented Sep 15, 2017

@user121216 Thanks for the explanation, and thanks for submitting the PR. Consistency with the way piwik handles other proxy details seems worthwhile. Looks good to me.

@fefrei

This comment has been minimized.

fefrei commented Nov 8, 2017

Thanks for this PR, @user121216! I'd love to see this merged as I'm running into this problem with the official Docker container.

@mattab mattab merged commit 57950ce into matomo-org:3.x-dev Nov 19, 2017

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
@mattab

This comment has been minimized.

Member

mattab commented Nov 19, 2017

Thanks for the PR @user121216 and to the others for the feedback. I've updated FAQ @ https://piwik.org/faq/how-to-install/faq_98/

@user121216 @fefrei @ToBeReplaced if you're using our official Docker Piwik image, could you please check / confirm if the Docker config is currently correct in terms of configuring proxy_set_header X-Forwarded-Uri /piwik; ? it would be great to clarify it in the README of the project, or maybe in the code something can be done (haven't checked). Thanks

@mattab

This comment has been minimized.

Member

mattab commented Nov 19, 2017

and if you have any feedback about the FAQ please let me know, i'm not 100% sure it is all correct or clear

@mattab mattab modified the milestones: 3.3.0, 3.2.1 Nov 19, 2017

@mattab mattab referenced this pull request Nov 19, 2017

Closed

Various bugs when using SSL and/or a reverse proxy #6880

1 of 4 tasks complete
@fefrei

This comment has been minimized.

fefrei commented Nov 20, 2017

It looks like https://hub.docker.com/r/_/piwik/ hasn't been updated yet, so I cannot test this in the moment.

@matomo-org matomo-org deleted a comment from MatomoForumBot Dec 4, 2017

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