ruby-on-railsapiauthenticationnginxactiveresource

Nginx Still Asking For Password When Loading Images


I am having a problem, I have set a nginx auth for my rails backend site which I am connecting with my rails frontend site using activeresource using self.user and self.password, everything works fine but when its loading images the backend site still asks for user name and login.

Any idea how to fix this?

Nginx config:

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

         server_names_hash_bucket_size 64;


        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # Phusion Passenger config
        ##
        # Uncomment it if you installed passenger or passenger-enterprise
        ##

         passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
         passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

nginx site config:

server {
        listen 80;
        listen [::]:80;

        server_name servername.com;
        passenger_enabled on;
        passenger_friendly_error_pages on;
        passenger_ruby /home/deploy/.rvm/gems/ruby-2.3.1/wrappers/ruby;
        rails_env    production;
        root /home/deploy/project_name/current/public/;

       location / {
         passenger_enabled on;
         auth_basic "Authorization Required";
         auth_basic_user_file /etc/nginx/.htpasswd;
       }

Solution

  • I fixed this issue by adding an exception for image files.

    location ~* \.(jpe?g|png|gif|ico)$ {
      satisfy any;
      auth_basic off;
    }