I want to grant public access to a hosted Website (nginx) and exclude a specific IP-Address range (123.456) from accessing it.
To say it simple: Every access from the IP-Range 123.456 should be restricted by promting for Username/Password. Thats what I want to have.
Here my .htaccess.
AuthType Basic
AuthName "Go away!"
AuthUserFile /home/www/path-to-my/.htpasswd
Require valid-user
Order Allow,Deny
Allow from all
Deny from 123.456
Satisfy any
What I get when I am using it:
Public access successful
Access from the excluded IP-Range = Timeout
As fas as I know .htaccess files are only for apache web server and not nginx.
Yo'll need to convert the rules with a converter or do it yourself.
In your case:
# nginx configuration
auth_basic "Go away!";
auth_basic_user_file /home/www/path-to-my/.htpasswd;
deny 123.456;
satisfy any;
The configuration directives are quite similar, but they are different.
Related
I have a subdomain that uses file_get_contents in php, and I need that to access an otherwise restricted file. In my .htaccess I have
<Files "file.txt">
Order Allow,Deny
Allow from subdomain.site.com
Deny from all
</Files>
The main problem I have here is that it doesn't unblock access from subdomain.site.com. I can't access the subdomain via url path because of site isolation set in place by my hosting provider.
The tutorial I have found says that you can whitelist certain websites to access this file. But, for some reason even following their syntax, it for some reason won't whitelist that site.
Tutorial:
https://www.askapache.com/htaccess/#developing_sites
I have got a client who I did a great website for a year or so ago however he has just sold his business and as part of the deal he wants me to take the website down. He has however agreed to allow me to use the website on my portfolio so I essentially want to be able to block all entries except from entries from my domain name, is this possible? I was thinking the best solution will be .htaccess but I am not the best at .htaccess so any advise would be awesome.
Something like this should work. Put it in the directory that requires the denial.
I would suggest an alternative method though; perhaps moving the site to your own server.
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName OnlyFromUNO
<Limit GET>
order deny,allow
deny from all
allow from .domain.com
</Limit>
this is my htaccess file:
AuthType Basic
AuthName “Sorry, Restricted Area!”
AuthUserFile /path/to/your/.htpasswd
Require valid-user
Allow from 123.45.67.890
Satisfy Any
My question is about the Allow from line ... the IP I give here is the callers IP, isnt it? This htaccess file is on my server which has 123.45.67.890 as IP, but as soon as I activate this htaccess, I can call the website it protects from anywhere, not just from the server itself, which is the plan. I call it like this: http://123.45.67.890/website ... question is, why can I call it from any computer even though it has the IP restriction? The site should onlybe called from the server itself.
Thanks :)
Because you need to deny from all first:
order deny,allow
deny from all
allow from 888.888.888.888
So I want to restrict access to a url. Now if they are coming from a given IP address then they shouldn't be prompted for a password. If they are not coming from a givin IP address then they should be prompted for a password.
so a either or of:
AuthUserFile /some/path/.htpasswd
AuthName "Please Log In"
AuthType Basic
require valid-user
and:
order deny,allow
deny from all
allow from x.x.x.x
You can use the Apache "Satisfy" directive.
Here is an example of using it :
AuthType Basic
AuthName "Please Log In"
AuthUserFile /some/path/.htpasswd
Require valid-user
Order deny,allow
Deny from all
Allow from 127.0.0.1
Satisfy any
Access without password is only allowed from 127.0.0.1.
Hope this helps.
With Apache 2.4 Satisfy is still available, but deprecated
Note
The directives provided by mod_access_compat have been deprecated by mod_authz_host. Mixing old directives like Order, Allow or Deny with new ones like Require is technically possible but discouraged. This module was created to support configurations containing only old directives to facilitate the 2.4 upgrade. Please check the upgrading guide for more information.
In your case Allow from 1.2.3.4 is replaced by Require ip 1.2.3.4
Combining several Requires (like Require valid-user and Require ip) can be done by Authorization Containers. So saying the client must either provide a password or come from a specific IP address, would be done by surrounding the directives with RequireAny, e.g.
<RequireAny>
Require valid-user
Require ip 1.2.3.4
</RequireAny>
Although, this is a special case as described at the end of Require
When multiple Require directives are used in a single configuration section and are not contained in another authorization directive like <RequireAll>, they are implicitly contained within a <RequireAny> directive. Thus the first one to authorize a user authorizes the entire request, and subsequent Require directives are ignored.
In other words, RequireAny is optional here, and you can just list
Require valid-user
Require ip 1.2.3.4
This workes perfect for me:
AuthType Basic
AuthName "myserver publicname"
AuthUserFile "/myserverpath/.htpasswds/public/passwd"
require ip 100.12.255.233
require valid-user
Note:
Just placed 'require ip' with 'my example ip' before 'require valid-user' and it does the trick. I can log in from my ip without password requested, but if I access from other locations or my mobile devices I need the password.
To set 'Satisfy any' was NOT GOOD FOR ME (!), because it disabled other .htaccess settings in lower hierarchy of my app and made my site insecure.
I need to protect a clients CMS with a username and password, only one username is needed. I was going to use htaccess because its so quick to add.
I'll be adding it using the password directories feature in WHM which stores the passwords here:
AuthUserFile "/home/username/.htpasswds/public_html/cms/passwd"
How secure is this? Are there ways to get into folders such as .htpasswds?
Straight from Apache's documentation
The most common method is Basic, and this is the method implemented by mod_auth_basic. It is important to be aware, however, that Basic authentication sends the password from the client to the server unencrypted. This method should therefore not be used for highly sensitive data, unless accompanied by mod_ssl. Apache supports one other authentication method: AuthType Digest. This method is implemented by mod_auth_digest and is much more secure. Most recent browsers support Digest authentication.
Please read the rest HERE
Please read the comments, things have changed since 2011. Good catch #reve_etrange
You should deny access to the folder that contains passwd files
<Directory /home/*>
Order allow,deny
Deny from all
Satisfy all
</Directory>
also don't forget that http traffic can be captured, so it won't suit for financial transactions.
As long as you set up the proper restrictions in your httpd.conf file to block external requests for .htaccess, and .htpasswd you should be okay.
You can block external requests (in Apache) with the following directives:
# The following code hides .htaccess and .htpasswd files from sites visitors.
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>