AWS上有两个EC2实例。 我使用NGINX 1.6。 这两个实例都连接到AWS负载平衡器。 为了将这些实例视为“正在运行”,负载均衡向两台服务器发送了一个HTTP请求,期望结果为200(OK)。
现在,我想密码保护两个实例的Web访问。 为此,我在NGINXconfiguration中使用了这些:
auth_basic "Restricted"; auth_basic_user_file /var/www/mywebapp/public/.htpasswd
问题是,没有办法告诉AWS的凭据,一旦你启用密码保护,这两个实例几乎立即被认为outOfService ,不再解决。
我想在NGINXconfiguration中定义一个端点,说/heartbeat将提供一个文件,在我的公共文件夹中说itsok.html文件,而不需要进行凭证检查,同时保持所有其他端点的密码保护我的networking应用程序
到目前为止,我所有的尝试都失败了。 我如何做到这一点?
这是我目前的NGINXconfiguration文件:
# Default server configuration # server { # Useful logs for debug. access_log /var/www/laravel/access.log; error_log /var/www/laravel/error.log; rewrite_log on; listen 80; server_name mywebapp.com; root "/var/www/mywebapp/public"; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/mywebapp/public; } auth_basic "Restricted"; auth_basic_user_file /var/www/mywebapp/public/.htpasswd; # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
尝试添加这个位置,或类似的东西。 我没有尝试过,但似乎相当微不足道。 在负载平衡器请求的指定目录中有一个文件。
location /heartbeat { root /var/www/whatever/; auth_basic off; }
您可以交替定义一个可能更有用的单个PHP文件,因为它会显示整个堆栈已经启动。 这可能是这样的,但它会依赖于那个PHP文件。 它可以输出“成功”或“失败”的基础上打一个数据库,或其他任何你想做的事情。
location = load-balancer-test.php { auth_basic off; # This is the only new bit try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
如果它不起作用,你应该玩,因为这个想法可能是正确的。 如果在尝试此操作并描述行为时,所有其他操作都无法访问/错误日志。