我有以下nginx配置我想添加基本身份驗證到這個配置。如何添加基本身份驗證到一個nginx配置與重寫
upstream phpfcgi {
server 127.0.0.1:7777;
# server unix:/var/run/php5-fpm.sock; #for PHP-FPM running on UNIX socket
}
server{
listen 80;
server_name qu.abc.com;
root /home/qu/website/current/web;
location/{
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
我編輯的位置塊到這個
location/{
# try to serve file directly, fallback to rewrite
auth_basic "Restricted";
auth_basic_user_file /home/qu/website/current/web/.htpassword;
try_files $uri @rewriteapp;
}
但是這一次不重寫工作。 有人可以幫忙。
嗨@PravinMishra我已經嘗試從中適應。我得到的問題是在服務器檢查basic_auth之前完成重寫。所以我需要通過首先檢查basic_auth來完成這項工作,然後進行重寫。或者可能有一些替代方法來做到這一點。 –