WordPress.org

Ready to get started?Download WordPress

Forums

podPress
[resolved] Statistics on nginx (22 posts)

  1. andrebazaglia
    Member
    Posted 1 year ago #

    Hello,

    I run nginx and would like to set up statistics on podPress. There are three methods to do that offered by the plugin. The first one (default) is "Use WP Permalinks", the second one is "Optional Files podpress_trac directory" and the third one is "Use download.mp3". The two first methods requires some specific configuration on Apache, and the third method ("Use download.mp3") may be easer to configure for me – that's the method I would like to choose.

    The podpress asks me to configure your web server to process .mp3 files the same way it does .php files in order to get it working:

    "Use download.mp3" - This is an alternative to using an .htaccess file. This is provided for sites which run webservers that do not use the .htaccess file for configuration, such as Microsoft Internet Information Server (IIS).
    To use this option, you will need to configure your web server to process .mp3 files the same way it does .php files. This is only necessary for the podPress directory, so that the download.mp3 file will be processed as a .php file.

    So, how can I configure this on nginx? Can someone help me changing nginx configuration?

    Thanks.

    http://wordpress.org/extend/plugins/podpress/

  2. andrebazaglia
    Member
    Posted 1 year ago #

    Update: This is the content in my nginx configuration, if it helps:

    server {
    listen 80;
    server_name localhost;
    root /var/www/html;
    index index.html index.php index.htm;
    include /var/www/html/nginx.conf;
    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

    #charset koi8-r;
    #access_log /var/log/nginx/log/host.access.log main;

    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
    }

    }

  3. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Hi André,

    you may use the option "Use WP Permalinks". When you use this option, you need to use also a non-default Permalink scheme like "Day and Name" (see Permalink screen).
    You are right on Apache servers WP creates .htaccess files. nginx uses the nginx.conf and other files which are not stored in the folder of the blog instead.
    I'm no nginx expert. I followed the examples http://wiki.nginx.org/WordPress and http://codex.wordpress.org/Nginx . As far as I can read your configuration, I would say that a non-default Permalink scheme should work.
    I believe the lines

    location / {
    	try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    make it possible.

    Does non-default Permalink scheme work in your blog? If it does work then you can use the option "Use WP Permalinks". (The description of this option is a little bit incomplete and maybe confusing.)

    Tim

  4. andrebazaglia
    Member
    Posted 1 year ago #

    Hi Tim,

    Firstly, thank you very much for the reply. I just changed all my nginx config files following the http://codex.wordpress.org/Nginx examples strictly, and defined the option Use WP Permalinks, just like you said. I already use non-default Permalink scheme.

    You can to see the situation in two examples:

    - Here's a post example: http://ipodschool.com/2013/01/facebook-introduz-mensagens-de-voz-exclusivas-para-o-messenger-movel/ (as you can see, I use non-default permalinks working fine)

    - Here's the link that podpress is using: http://ipodschool.com/podpress_trac/web/45699/0/ipscast-27.1.mp3 (as you can see, I got a 404 error).

    As I just changed all my nginx configuration to the WordPress recommendation from the link you sent me one and it still not working, do you have any other ideas?

    Thanks.

  5. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    No not really. But I can give you my .conf files. This way you may discover a relevant difference.

    My configuration is one for a nginx stack on my local computer and the blog is in the sub folder wp34en/. If you think about using these files then you need to adjust all values according to the location of the blog on your server.

  6. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I have made 2 changes compared to the example on http://codex.wordpress.org/Nginx :

    • worker_processes 1; instead of worker_processes 2;
      (I have installed my nginx stack on a Windows computer and if I set this value to one I get 2 process which are enough.)
    • rewrite ^ $scheme://mysite.com$uri redirect; instead of rewrite ^ $scheme://mysite.com$request_uri redirect;
      (This better when you use the default Permalinks scheme. Using $request_uri doubled the query arguments.)
  7. andrebazaglia
    Member
    Posted 1 year ago #

    You just used the WordPress codex config, just like me. Our settings are almost the same, I can see just one difference in our configs:

    You is using:

    server {
                    server_name  _;
                    #rewrite ^ $scheme://localhost$request_uri redirect;
                    rewrite ^ $scheme://localhost$uri redirect;
            }

    I am using the line you commented, that is as WordPress Codex shows. What's the difference between request_uri and uri? That's the only one differente in our codes.

  8. andrebazaglia
    Member
    Posted 1 year ago #

    Oh yes, I'm using worker_processes 2, but that really doesn't matter.

  9. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    The difference is that if I use rewrite ^ $scheme://localhost$request_uri redirect; then I get sometimes doubled query arguments.

  10. andrebazaglia
    Member
    Posted 1 year ago #

    Still not working – what's really crazy as we are on same configs! Your plugin have two other alternatives to get statistics. Is there a way to use any other of this other alternatives with nginx?

  11. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I noticed that you use a Cache plugin. Deactivating this plugin is no solution. But it would be interesting to know whether it would make a difference. I do not use such plugin.

    Furthermore I placed my audio files in a sub folder of the wp-content/ folder. The media files of your blog seem to be in a sub folder directly below the domain. Maybe some of the restrictions prevent the access to this folder for the podPress script. Could you try to place a media file also in a sub folder of the wp-content/ folder?

    Is there a way to use any other of this other alternatives with nginx?

    The second method may work. (It works on my system but the WP Permalinks method works too.)
    The third method (download.mp3) will probably not work with your current setup. (It does not work with my configuration.)

  12. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I have made a further test and placed a media file in a folder outside and above the wp-content/ folder (e.g. http://localhost/wp34en/podcasts/hallo3.mp3) and the "Use WP Permalinks" method still works with my configuration.

  13. andrebazaglia
    Member
    Posted 1 year ago #

    You just discovered the problem! I really use W3TC cache plugin, and it has an "include" in nginx that adds this code in my config file: http://nopaste.me/paste/1660259550e70a775a26e

    Removing this included content, podPress statistics works. Do you have any idea about how to have both W3TC and podPress working?

  14. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I read the page again and found this section http://codex.wordpress.org/Nginx#URL_Rewrites_.2F_Permalinks which may be of interest.
    Further it seems to be necessary to have additional settings in case one uses one of the famous Cache plugins. In the example of the wordpress.conf on that page you can see the lines

    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-ms-subdir-wp-super-cache.conf;
    #include global/wordpress-ms-subdir-w3-total-cache.conf;

    and there further notes e.g. here
    http://codex.wordpress.org/Nginx#W3_Total_Cache_Rules

    Maybe you could try to add a further exception rule to the lines

    # Don't cache uris containing the following segments
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
            set $cache_uri 'null cache';
    }

    When the statistics feature is active then the URLs of the podPress media files will always contain the phrase /podpress_trac.

    The principle behind the podPress statistics is that it does masks certain media files URLs during the page request like
    http://example.com/podpress_trac/web/9/0/example.mp3.
    web is one of 3 download ways (web, feed, play). The following number (here 9) is the post ID which is followed by the index of the media file in the post (0 means it is the first one in a post).
    If someone clicks on the player or one of the download links podPress will notice that and send a HTTP 302 redirect with the real URL of the media file.

    If you click on a download link of a media files added with podPress then you should be able see the request and the redirect in the log files access.log of your server. What does can you see? Or does the error.log contain an error?

  15. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Ah okay, I read your last post just now. Maybe there is a way to exclude podPress URLs somehow.

    (I need a few minutes.)

  16. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    I would try to add an exception for request URLs which contain the phrase podpress_trac.
    Try to add

    if ($request_uri ~* "/\/podpress_trac\/") {
        set $w3tc_rewrite 0;
    }

    or

    if ($request_uri ~* "podpress_trac") {
        set $w3tc_rewrite 0;
    }

    to this .conf file (http://nopaste.me/paste/1660259550e70a775a26e).
    Maybe after line 39.

  17. andrebazaglia
    Member
    Posted 1 year ago #

    Hi,

    Firstly, thank you very much for the attention.

    I tried to do what you told me, but than I got this when starting nginx:

    "directive "if" has no opening "{"

    Than I tried to write the config you sent me like this:

    if ($request_uri ~* "("/\/podpress_trac\/")") {
        set $w3tc_rewrite3 0;
    }

    Nginx started successfully, but I still getting 404 error in podpress links.

    Update: Now I just copied/pasted exactly what you sent me, but still not working. :(

    Any more ideas?

  18. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Using " in this code snippet is not correct and will not lead to the desired result.
    This IF condition checks with a regular expression whether the variable $request_uri contains a string which contains the phrase /podpress_trac/. All between the double quotation marks is the search phrase. Because it is a regular expression, it is necessary to escape slashes with backslashes. If one wants to search for /podpress_trac/ then the regexp is \/podpress_trac\/.

    However, please try the second variation:

    if ($request_uri ~* "podpress_trac") {
        set $w3tc_rewrite 0;
    }

    (Please, write the double quotation marks manually with your keyboard into the .conf file. Maybe there was a problem during the copy and paste process.)

    If this is helping either then a further idea could be to remove |mp3 and |m4a (and maybe other media file extensions) from line 24.

  19. andrebazaglia
    Member
    Posted 1 year ago #

    Yes, THIS WORKED!! Thank you so much.

    I removed mp3 and m4a from the extesions list from line 24 and also added the code you sent me in the config file. However, the

    if ($request_uri ~* "podpress_trac") {
        set $w3tc_rewrite 0;
    }

    is making no diference (with or without this code, the result it the same, the import is to remove mp3 and m4a from line 24). Do you recommend me to add this podpress_trac exception just for safety or as the redirect is working only removing mp3/m4a extentions, nothing else is necessary?

  20. ntm
    Member
    Plugin Author

    Posted 1 year ago #

    Do you recommend me to add this podpress_trac exception just for safety

    No. If the 404 error occurred despite using the podpress_trac exception then it is better if you do not leave this IF condition in the .conf file.

    But I have looked one more time into your .conf file and now I'm surprised that removing the file name extensions should have this effect. It seems that I was a little bit hasty with my suggestion to remove the file extensions from line 24. As I read this line now, it seems to make the server add a further line to the HTTP Header. But it is probably not the same as the exception e.g. in lines 52-54.
    On the other hand removing the file name extension seems to help.

    In conclusion remove

    if ($request_uri ~* "podpress_trac") {
        set $w3tc_rewrite 0;
    }

    But if the download does not work tomorrow then add these line again.

  21. andrebazaglia
    Member
    Posted 1 year ago #

    Nice, Tim. Thank you again. It's great to have podPress working fine. Congratulations for your great plugin. :)

  22. ghelleks
    Member
    Posted 1 year ago #

    A proper solution to this problem is to disable W3TC's X-Powered-By header for media files altogether. This way, you don't need to edit nginx.conf by hand each time you change a w3tc setting.

    Under "Performance" > "Browser Cache" > "Media & Other Files", disable/uncheck "Set W3 Total Cache header".

    Anyone using nginx + podPress + W3TC will want to do this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic