我有一个相对简单的configuration:
upstream appserver-1 { server unix:/var/www/example.com/app/tmp/gunicorn.sock fail_timeout=0; } server { listen 80; server_name example.com; location / { proxy_pass http://appserver-1; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; auth_basic "Restricted"; auth_basic_user_file /path/to/htpasswd; } location /api/ { auth_basic off; } }
目标是在整个网站上使用基本authentication,除了/api/
subtree。 虽然它在基本身份validation方面工作,但其他指令(如proxy_pass
在/api/
上也不起作用。
是否有可能只是禁用基本身份validation,同时保留其他指令,而不复制和粘贴一切?
两个文件怎么样?
包括/ proxy.conf将是:
proxy_pass http://appserver-1; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
而你目前的conf文件:
upstream appserver-1 { server unix:/var/www/example.com/app/tmp/gunicorn.sock fail_timeout=0; } server { listen 80; server_name example.com; location / { auth_basic "Restricted"; auth_basic_user_file /path/to/htpasswd; include includes/proxy.conf; } location /api/ { auth_basic off; include includes/proxy.conf; } }
在Nginx 1.4.4中, auth_basic
设置需要引号。
location / { auth_basic "Restricted"; auth_basic_user_file /etc/nginx/passwd; include /etc/nginx/uwsgi_params; uwsgi_pass unix:/tmp/app.sock; } location /api { auth_basic "off"; include /etc/nginx/uwsgi_params; uwsgi_pass unix:/tmp/app.sock; }
安装apache2-utils
,有一个很好的帮助程序,可以很快为你创buildhtpasswd文件。 http://httpd.apache.org/docs/2.2/programs/htpasswd.html
htpasswd -c -m <filename> <username>
下面的configuration适用于我共享文件夹从我的磁盘没有任何身份validation共享文件夹和其余的网站所需的身份validation
server { listen 80; server_name localhost; root C:\\Users\\Work\\XYZ\\; autoindex on; autoindex_exact_size off; autoindex_localtime on; auth_basic "Administrator Login"; auth_basic_user_file C:\\Users\\Work\\.htpasswd; location /share { auth_basic "off"; allow all; # Allow all to see content alias C:\\Users\\sg32884\\Work\\share\\; } }