• Resolved andrebazaglia

    (@andrebazaglia)


    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.

    https://www.ads-software.com/extend/plugins/podpress/

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter andrebazaglia

    (@andrebazaglia)

    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;
    }

    }

    Plugin Author ntm

    (@ntm)

    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 https://wiki.nginx.org/WordPress and https://codex.www.ads-software.com/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

    Thread Starter andrebazaglia

    (@andrebazaglia)

    Hi Tim,

    Firstly, thank you very much for the reply. I just changed all my nginx config files following the https://codex.www.ads-software.com/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: https://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: https://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.

    Plugin Author ntm

    (@ntm)

    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.

    Plugin Author ntm

    (@ntm)

    I have made 2 changes compared to the example on https://codex.www.ads-software.com/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.)
    Thread Starter andrebazaglia

    (@andrebazaglia)

    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.

    Thread Starter andrebazaglia

    (@andrebazaglia)

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

    Plugin Author ntm

    (@ntm)

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

    Thread Starter andrebazaglia

    (@andrebazaglia)

    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?

    Plugin Author ntm

    (@ntm)

    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.)

    Plugin Author ntm

    (@ntm)

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

    Thread Starter andrebazaglia

    (@andrebazaglia)

    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: https://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?

    Plugin Author ntm

    (@ntm)

    I read the page again and found this section https://codex.www.ads-software.com/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
    https://codex.www.ads-software.com/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
    https://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?

    Plugin Author ntm

    (@ntm)

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

    (I need a few minutes.)

    Plugin Author ntm

    (@ntm)

    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 (https://nopaste.me/paste/1660259550e70a775a26e).
    Maybe after line 39.

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Statistics on nginx’ is closed to new replies.