我遇到了问题,我为我的rails后端站点设置了一个nginx auth,我使用active.ource使用self.user和self.password连接我的rails前端站点,一切正常但是当它加载图像后端时网站仍然要求用户名和登录。
知道怎么解决这个问题吗?
Nginx配置:
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网站配置:
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;
}
答案 0 :(得分:0)
我通过为图片文件添加例外来修复此问题。
location ~* \.(jpe?g|png|gif|ico)$ {
satisfy any;
auth_basic off;
}