Page 1 of 2 1 2 LastLast
Results 1 to 15 of 24
Like Tree1Likes

nginx location directive

This is a discussion on nginx location directive within the General Discussion forums, part of the vBulletin SEO Discussion category; Hi, I'm trying to protect vbseocp.php and other locations in nginx using this directive, but doesn't work: # vBSeo CP ...

  1. #1
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times

    nginx location directive

    Hi,

    I'm trying to protect vbseocp.php and other locations in nginx using this directive, but doesn't work:

    # vBSeo CP
    location /forum/vbseocp.php/ {
    auth_basic "Restricted";
    auth_basic_user_file htpasswd;
    }

    Do you know if it's possible to add more than one location in the same directive:

    location ~ ^/forum(admincp|modcp|vbseocp.php)/ {

    As was looking to add another level of protection to admincp, modcp and vbseocp.php, bur the above example doesn't work :(

    Anyone knows?

    Thanks

  2. #2
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Please try to remove ending slash:
    location /forum/vbseocp.php {
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  3. #3
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    I already saw that, but it doesn't work.
    Do you know if I can place multiple directives like this:

    location ~ ^/forum(admincp|modcp|vbseocp.php)/ {

  4. #4
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Yes, this is allowed: NginxHttpCoreModule - Nginx Wiki
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  5. #5
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    I'm having some troubles adding a 2nd level of protection using auth I discover that there is a strange behavior in the way we do this.

    Code:
    location /forum/admincp/ {
            auth_basic            "Restricted";
            auth_basic_user_file  htpasswd;
    }
    The above example as this behavor:

    /forum/admincp -> Is protected
    /forum/admincp/ -> Is protected
    /forum/admincp/index.php -> Is not protected

    This is very odd.

    Next ... I would like to protect in one rule /forum/admincp/ | /forum/admincp/ | /forum/vbseco.php but I cant get it to work

    You can see my actual configuration for this vhost in the attachment.
    Attached Files
    Last edited by nfn; 01-27-2009 at 09:55 AM.

  6. #6
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Please check if it works with vBSEO rewrite rules temporarily removed (may be they are conflicting).
    Also, try to put auth section at the bottom of config (below rewrite rules).
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  7. #7
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    Ok ..

    Removing vBSeo rules has the same behavior.
    Placing in the bottom as the same behavior.
    Tested in another domain in the same server has a similar behavior.
    Tested locally in my local server and using the default configuration works.

    Is my nginx configuration attached ok?

  8. #8
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Yes, the config looks ok. Try to change auth section to:
    Code:
            location ~ /forum/admincp/.* {
                    auth_basic            "Restricted";
                    auth_basic_user_file  htpasswd;
            }
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  9. #9
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    Hi Oleg

    After some tests, I think this is a conflict with FastCGI. If i try admincp/index.php or other .php file, it fails.
    With other extensions, I don't have problems; ex: admincp/file.txt or admincp/thisisafile.html

  10. #10
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    Confirmed ...
    I removed the FastCGI directive, everything will be as expected:

    Code:
    location ~ \.php$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param   SCRIPT_FILENAME  /home/xxxxx/public$fastcgi_script_name;
            include         fastcgi_params;
    }

  11. #11
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    And that's even with auth section moved to the bottom? If you can provide us with server access details via support ticket, we'll check this further.
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  12. #12
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Update.

    I've used this for auth section (at the top of config):
    Code:
            location ~ /forum/(admincp/|modcp/|vbseocp\.php).* {
                    root    /home/***/public/;
                    auth_basic            "Restricted";
                    auth_basic_user_file  htpasswd;
           }
    and updated second vBSEO rewrite section to:
    Code:
            if ($request_filename ~ "\.php$" ) {
            rewrite  ^(.*(admincp/|modcp/|vbseocp\.php).*) $1 last;
            rewrite ^(/forum/.*)$ /forum/vbseo.php last;
          }
    and that worked.
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  13. #13
    nfn
    nfn is offline
    Senior Member
    Real Name
    Nuno
    Join Date
    Feb 2008
    Location
    Portugal
    Posts
    276
    Liked
    1 times
    Hi Oleg,

    Thanks for your help once again. Now it's works as it should
    I take the liberty to place here a fully functional nginx vhost for vBulletin & vBSeo with an additional layer of security using a protected area for admincp, modcp and vbseocp.php.

    Code:
    server {
            listen   80;
            server_name  example.com;
            rewrite ^/(.*) http://www.example.com/$1 permanent;
    }
    
    server {
            listen   80;
            server_name www.example.com;
    
            access_log /home/www/public_html/example.com/logs/access.log;
            error_log /home/www/public_html/example.com/logs/error.log;
    
            root   /home/www/public_html/example.com/public/;
            index  index.html index.php;
    
            # vBulletin & vBSeo Restricted
            location ~ /forum/(admincp/|modcp/|vbseocp\.php).* {
                    root    /home/www/public_html/example.com/public/;
                    auth_basic            "Restricted";
                    auth_basic_user_file  htpasswd;
            }
    
            # FastCGI
            location ~ \.php$ {
                    fastcgi_pass    127.0.0.1:9000;
                    fastcgi_index   index.php;
                    fastcgi_param   SCRIPT_FILENAME  /home/www/public_html/example.com/public$fastcgi_script_name;
                    include         fastcgi_params;
            }
    
            # Expire Header for Images
            location ~* ^.+.(jpg|jpeg|gif|png|ico|css|js)$ {
                    root    /home/www/public_html/example.com/public/;
                    access_log      off;
                    expires 30d;
            }
    
            # vBSeo - Start
            location /forum/ {
    
                    rewrite ^/forum/((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ /forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 last;
    
                    if (!-e $request_filename) {
                            rewrite ^(/forum/.*)$ /forum/vbseo.php last;
                    }
    
            }
    
            if ($request_filename ~ "\.php$" ) {
                    rewrite  ^(.*(admincp/|modcp/|vbseocp\.php).*) $1 last;
                    rewrite ^(/forum/.*)$ /forum/vbseo.php last;
            }
            # vBSeo - End
    }
    Note:the path's must be edited to match your configuration
    Reference for http_auth module: NginxHttpAuthBasicModule - Nginx Wiki

  14. #14
    Senior Member webwizzy's Avatar
    Real Name
    Vinayak
    Join Date
    Aug 2008
    Location
    India
    Posts
    257
    Liked
    0 times
    Quote Originally Posted by Oleg Ignatiuk View Post
    Update.

    I've used this for auth section (at the top of config):
    Code:
            location ~ /forum/(admincp/|modcp/|vbseocp\.php).* {
                    root    /home/***/public/;
                    auth_basic            "Restricted";
                    auth_basic_user_file  htpasswd;
           }
    and updated second vBSEO rewrite section to:
    Code:
            if ($request_filename ~ "\.php$" ) {
            rewrite  ^(.*(admincp/|modcp/|vbseocp\.php).*) $1 last;
            rewrite ^(/forum/.*)$ /forum/vbseo.php last;
          }
    and that worked.
    Hello,

    Two questions please:-

    1. Where does the htpasswd file resides?

    2. And in the second part of the code - What does the highlighted part does? Is it necessary?

    Thanks

  15. #15
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    1. It's relative to nginx config folder.

    2. It tells vBSEO NOT to process requests that are protected.
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 12
    Last Post: 02-09-2010, 03:37 PM
  2. nginx
    By Smiggy in forum Pre-Sales Questions
    Replies: 1
    Last Post: 01-07-2009, 02:21 PM
  3. nginx
    By fras in forum General Discussion
    Replies: 3
    Last Post: 01-25-2008, 07:57 PM
  4. Unable to match directive-apache update error
    By poprulz in forum URL Rewrite Settings
    Replies: 0
    Last Post: 01-16-2008, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •