Apache rails beta solutions for site access

I am creating a site ror and ask to put a temporary access restriction on it. All that is needed is a general access restriction that will be used by beta users. The site is deployed on an Apache server (on Mac) using a passenger. I am wondering what solutions are there?

+2


a source to share


3 answers


I answered a similar question yesterday with a simple solution in Rails; I am using this solution to protect my development site from learning while testing. I've tried it below for convenience.


Rails has a built-in helper for this, you can put this in your application controller:

protected
  def authenticate
    authenticate_or_request_with_http_basic do |username, password|
      username == "admin" && password == "test"
    end
  end

      

Then use the before_filter file on any controllers you want to protect (or just paste it into your app controller to block the entire site):

before_filter :authenticate

      

This method works with both Nginx and Apache, which is an added bonus. However, it does not work if full page caching is enabled β€” since the visitor is never pushed onto the Rails stack; he won't kick.

Edit Just noticed that you specified the route / admin. All my admin controllers inherit from AdminController. You can customize your settings like this:



/app/controllers/admin/admin_controller.rb

class Admin::AdminController < ApplicationController
  before_filter :authenticate
  protected
    def authenticate
      authenticate_or_request_with_http_basic do |username, password|
      username == "admin" && password == "test"
    end
  end
end

      

Then all controllers extend the admin controller, for example:

class Admin::ThingsController < Admin::AdminController

      

My routes are configured like this:

map.namespace :admin do |admin|
    admin.resources :things
end

      

Hope it helps.

+4


a source


Here is my first look at it using a nice old htaccess solution I found surprisingly little information on rails. Create user / password file for beta user:

mysite> htpasswd -c .htpasswd beta
mysite> chmod 755 .htpasswd

      

Create an access config file in rails public dir 'public / .htaccess' containing:

AuthName "Enter password"
AuthType Basic
AuthUserFile /Users/myuser/projects/mysite/.htpasswd
require user beta

      



Change file permissions:

mysite> chmod 755 public/.htaccess

      

Modify the apache conf file (find out where it is: apachectl -V | grep SERVER_CONFIG_FILE). In the VirtualHost config section, add the following to define what is used in the htaccess file:

AllowOverride All

      

0


a source


Prefinery provides you with a turnkey solution for this type of scenario http://www.prefinery.com/

0


a source







All Articles