Apache Authentication in htaccess
Require password for 1 file only
<files login.php> Order deny,allow Deny from all AuthName "htaccess password prompt" AuthType Basic AuthUserFile /web/askapache.com/.htpasswd Require valid-user </Files>
Protect multiple files:
<FilesMatch "^(exec|env|doit|phpinfo|w).*$"> Order deny,allow Deny from all AuthName "htaccess password prompt" AuthUserFile /.htpasswd AuthType basic Require valid-user </FilesMatch>
Using the Apache Allow Directive in htaccess
network/netmask pair
Order deny,allow Deny from all Allow from 10.1.0.0/255.255.0.0
IP address
Order deny,allow Deny from all Allow from 10.1.2.3
More than 1 IP address
Order deny,allow Deny from all Allow from 192.168.1.104 192.168.1.205
Partial IP addresses, first 1 to 3 bytes of IP, for subnet restriction
Order deny,allow Deny from all Allow from 10.1 Allow from 10 172.20 192.168.2
network/nnn CIDR specification
Order deny,allow Deny from all Allow from 10.1.0.0/16
IPv6 addresses and subnets
Order deny,allow Deny from all Allow from 2001:db8::a00:20ff:fea7:ccea Allow from 2001:db8::a00:20ff:fea7:ccea/10
Deny subdomains
Order Allow,Deny Allow from apache.org Deny from wireshark.apache.org
Allow from IP without password prompt, and also allow from any address with password prompt
Order deny,allow Deny from all AuthName "htaccess password prompt" AuthUserFile /web/askapache.com/.htpasswd AuthType Basic Require valid-user Allow from 172.17.10.1 Satisfy Any
Skeleton .htaccess file to start with
I use this when I start a new site, and uncomment or delete parts of the file depending on the sites needsUltimate htaccess file sample
# # DEFAULT SETTINGS # Options +ExecCGI -Indexes DirectoryIndex index.php index.html index.htm ErrorDocument 400 /cgi-bin/error.php ErrorDocument 401 /cgi-bin/error.php ErrorDocument 403 /cgi-bin/forbidden.cgi ErrorDocument 404 /404.html ErrorDocument 405 /cgi-bin/error.php ErrorDocument 406 /cgi-bin/error.php ErrorDocument 409 /cgi-bin/error.php ErrorDocument 413 /cgi-bin/error.php ErrorDocument 414 /cgi-bin/error.php ErrorDocument 500 /cgi-bin/error.php ErrorDocument 501 /cgi-bin/error.php ### DEFAULTS ServerSignature Off AddType video/x-flv .flv AddType application/x-shockwave-flash .swf AddType image/x-icon .ico AddDefaultCharset UTF-8 AddLanguage en-US .html .htm .txt .xml .php SetEnv TZ America/Indianapolis SetEnv SERVER_ADMIN webmaster@askapache.com ### PHPINI-CGI #AddHandler php-cgi .php #Action php-cgi /cgi-bin/php5.cgi ### FAST-CGI #AddHandler fastcgi-script .fcg .fcgi .fpl #AddHandler php5-fastcgi .php #Action php5-fastcgi /cgi-bin/fastcgi.fcgi # # HEADERS and CACHING # # 1 YEAR <FilesMatch ".(flv|ico|pdf)$"> Header set Cache-Control "max-age=29030400, public" </FilesMatch> # 1 WEEK <FilesMatch ".(jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=604800, public" </FilesMatch> # 3 HOUR <FilesMatch ".(txt|xml|js|css)$"> Header set Cache-Control "max-age=10800" </FilesMatch> # 1 MIN <FilesMatch ".(html|htm|php)$"> Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate" Header set P3P "policyref="/w3c/p3p.xml", CP="NOI DSP COR NID CUR ADM DEV OUR BUS"" Header set imagetoolbar "no" </FilesMatch> # # REWRITES AND REDIRECTS # ### SEO REDIRECTS #Redirect 301 /ssl-ns.html /2006/htaccess/apache-ssl-in-htaccess-examples.html #Redirect 301 /ht.tml #Redirect 301 /index.html / #RedirectMatch 301 /2006/htaccess-forum/(.*) /2006/htaccess/$1 #RedirectMatch 301 /(.*)rfc2616(.*) http://rfc.askapache.com/rfc2616/rfc2616.html #RedirectMatch 301 /phpmanual(.*) /manual/en/$1 ### REWRITES RewriteEngine On RewriteBase / ### WORDPRESS #<ifModule mod_rewrite.c> #RewriteEngine On #RewriteBase / #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule . /index.php [L] #</ifModule> ### REQUIRE WWW #RewriteCond %{HTTP_HOST} !^www.askapache.com$ [NC] #RewriteRule ^(.*)$ /$1 [R=301,L] ### STOP LOOP CODE #RewriteCond %{ENV:REDIRECT_STATUS} 200 #RewriteRule ^.*$ - [L] ### REDIRECT BLOG FEED TO FEEDBURNER #RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator|Recent) [NC] #RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302] ### BLOCK WGET #RewriteCond %{HTTP_USER_AGENT} ^Wget.* [NC] #RewriteRule .* /cgi-bin/forbidden.cgi [L] # # AUTHENTICATION # ### BASIC PASSWORD PROTECTION #AuthName "Prompt" #AuthUserFile /web/askapache.com/.htpasswd #AuthType basic #Require valid-user ### UNDER CONSTRUCTION PROTECTION #AuthName "Under Development" #AuthUserFile /web/askapache.com/.htpasswd #AuthType basic #Require valid-user #Order Deny,Allow #Deny from all #Allow from 23.23.23.1 w3.org googlebot.com google.com google-analytics.com #Satisfy Any
Deploying an ASP.NET Web Application to a Windows Azure Web Site
Source: http://www.windowsazure.com/en-us/develop/net/tutorials/get-started/
This tutorial shows how to deploy an ASP.NET web application to a Windows Azure Web Site by using the Publish Web wizard in Visual Studio 2012 or Visual Studio 2012 for Web Express. If you prefer, you can follow the tutorial steps by using Visual Studio 2010 or Visual Web Developer Express 2010.
You can open a Windows Azure account for free, and if you don't already have Visual Studio 2012, the SDK automatically installs Visual Studio 2012 for Web Express. So you can start developing for Windows Azure entirely for free.
This tutorial assumes that you have no prior experience using Windows Azure. On completing this tutorial, you'll have a simple web application up and running in the cloud.
You'll learn:
For more information, see Web Sites: Management Support within the Visual Studio Server Explorer in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog.
To delete your web site, you can use the Windows Azure Management Portal. The following screen shot shows Stop, Restart, and Delete buttons in the Dashboard tab of the management portal.
You can change site settings on the Configure tab. For more information, see How to Manage Web Sites.
For more information, see How to Scale a Web Site. (Adding server resources to scale a web site is not free.)
For more information, see Web Sites: Streaming Diagnostic Logs in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog. For information about web site monitoring functions that are available from the management portal, see How to Monitor Web Sites.
This tutorial shows how to deploy an ASP.NET web application to a Windows Azure Web Site by using the Publish Web wizard in Visual Studio 2012 or Visual Studio 2012 for Web Express. If you prefer, you can follow the tutorial steps by using Visual Studio 2010 or Visual Web Developer Express 2010.
You can open a Windows Azure account for free, and if you don't already have Visual Studio 2012, the SDK automatically installs Visual Studio 2012 for Web Express. So you can start developing for Windows Azure entirely for free.
This tutorial assumes that you have no prior experience using Windows Azure. On completing this tutorial, you'll have a simple web application up and running in the cloud.
You'll learn:
- How to enable your machine for Windows Azure development by installing the Windows Azure SDK.
- How to create a Visual Studio ASP.NET MVC 4 project and publish it to a Windows Azure Web Site.
Note To
complete this tutorial, you need a Windows Azure account that has the
Windows Azure Web Sites feature enabled. If you don't have an account,
you can create a free trial account in just a couple of minutes. For
details, see Windows Azure Free Trial.
Tutorial segments
- Set up the development environment
- Create a web site in Windows Azure
- Create an ASP.NET MVC 4 application
- Deploy the application to Windows Azure
- Next steps
Set up the development environment
To start, set up your development environment by installing the Windows Azure SDK for the .NET Framework.- To
install the Windows Azure SDK for .NET, click the link that corresponds
to the version of Visual Studio you are using. If you don't have Visual
Studio installed yet, use the Visual Studio 2012 link.
Windows Azure SDK for Visual Studio 2012
Windows Azure SDK for Visual Studio 2010
- When you are prompted to run or save the installation executable, click Run.
- In the Web Platform Installer window, click Install and proceed with the installation.
- If you are using Visual Studio 2010 or Visual Web Developer 2010 Express, install MVC 4.
Create a web site
The next step is to create the Windows Azure web site.- In the Windows Azure Management Portal, click Web Sites, and then click New.
- Click Quick Create.
- In the Create Web Site step of the wizard, enter a string in the URL box to use as the unique URL for your application.
The complete URL will consist of what you enter here plus the suffix that you see next to the text box. The illustration shows example1, but if someone has already taken that string for a URL, you need to enter a different value. - In the Region drop-down list, choose the region that is closest to you.
This setting specifies which data center your web site will run in. - Click the Create Web Site arrow.
The Management Portal returns to the Web Sites page, and the Status column shows that the site is being created. After a while (typically less than a minute), the Status column shows that the site was successfully created. In the navigation bar at the left, the number of sites you have in your account appears next to the Web Sites icon.
Create an ASP.NET MVC 4 application
You have created a Windows Azure Web Site, but there is no content in it yet. Your next step is to create the Visual Studio web application project that you'll publish to Windows Azure.Create the project
- Start Visual Studio 2012 or Visual Studio 2012 for Web Express.
- From the File menu, click New, and then click Project.
- In the New Project dialog box, expand C# and select Web under Installed Templates, and then select ASP.NET MVC 4 Web Application.
- Ensure that .NET Framework 4.5 is selected as the target framework.
- Name the application MyExample and click OK.
- In the New ASP.NET MVC 4 Project dialog box, select the Internet Application template and click OK.
Run the application locally
- Press CTRL+F5 to run the application. The application home page appears in the default browser.
Deploy the application to Windows Azure
- In Visual Studio, right-click the project in Solution Explorer and select Publish from the context menu.
The Publish Web wizard opens. - In the Profile tab of the Publish Web wizard, click Import.
The Import Publish Profile dialog box appears. - If
you have not previously added your Windows Azure subscription in Visual
Studio, perform the following steps. In these steps you add your
subscription so that the drop-down list under Import from a Windows Azure web site will include your web site.
a. In the Import Publish Profile dialog box, click Import from a Windows Azure web site, and then click Add Windows Azure subscription.
b. In the Import Windows Azure Subscriptions dialog box, click Download subscription file.
c. In your browser window, save the .publishsettings file.
Security Note The .publishsettings file contains your credentials (unencoded) that are used to administer your Windows Azure subscriptions and services. The security best practice for this file is to store it temporarily outside your source directories (for example in the Libraries\Documents folder), and then delete it once the import has completed. A malicious user who gains access to the .publishsettings file can edit, create, and delete your Windows Azure services.
e. Click Import.
- In the Import Publish Profile dialog box, select Import from a Windows Azure web site, select your web site from the drop-down list, and then click OK.
- In the Connection tab, click Validate Connection to make sure that the settings are correct.
- When the connection has been validated, a green check mark is shown next to the Validate Connection button. Click Next.
- In the Settings tab, uncheck Use this connection string at runtime
option, since this application is not using a database. You can accept
the default settings for the remaining items on this page. You are
deploying a Release build configuration and you don't need to delete
files at the destination server, precompile the application, or exclude
files in the App_Data folder.
Click Next. - In the Preview tab, click Start Preview.
The tab displays a list of the files that will be copied to the server. Displaying the preview isn't required to publish the application but is a useful function to be aware of. In this case, you don't need to do anything with the list of files that is displayed. - Click Publish.
Visual Studio begins the process of copying the files to the Windows Azure server. - The Output window shows what deployment actions were taken and reports successful completion of the deployment.
- Upon successful deployment, the default browser automatically opens to the URL of the deployed web site.
The application you created is now running in the cloud.
Next steps
In this tutorial, you've seen how to deploy a simple web application to a Windows Azure Web Site. Other resources are available to show you how to manage, scale, and troubleshoot the site, how to add database, authentication, and authorization functionality, and how to decide if your application should run in a Windows Azure Cloud Service instead of a Windows Azure Web Site.How to manage a web site
When you're done with the site, you can delete it, and at times you might want to take it offline temporarily or change site settings. You can do some of these functions right from Server Explorer in Visual Studio.For more information, see Web Sites: Management Support within the Visual Studio Server Explorer in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog.
To delete your web site, you can use the Windows Azure Management Portal. The following screen shot shows Stop, Restart, and Delete buttons in the Dashboard tab of the management portal.
You can change site settings on the Configure tab. For more information, see How to Manage Web Sites.
How to scale a web site
When your site is public and it starts to get more traffic, response times might slow down. To remedy that, you can easily add server resources in the Scale tab of the management portal.For more information, see How to Scale a Web Site. (Adding server resources to scale a web site is not free.)
How to troubleshoot a web site
If the site stops working correctly, you might want to look at trace or log output for help with troubleshooting. Visual Studio provides built-in tooling to make it easy to view Windows Azure logs as they are generated in real time.For more information, see Web Sites: Streaming Diagnostic Logs in Announcing the release of Windows Azure SDK 2.0 for .NET on ScottGu's blog. For information about web site monitoring functions that are available from the management portal, see How to Monitor Web Sites.
How to add database and authorization functionality
Most production web sites use a database and restrict some site functions to certain authorized users. For a tutorial that shows how to get started with database access, authentication, and authorization, see Deploy a Secure ASP.NET MVC app with Membership, OAuth, and SQL Database to a Windows Azure Web Site.How to decide if your application should run in a Cloud Service
In some scenarios you might want to run your application in a Windows Azure Cloud Service instead of a Windows Azure Web Site. For more information, see Windows Azure Execution Models. For a tutorial series that shows how to create a multi-tier ASP.NET web application and deploy it to a Cloud Service, see .NET Multi-Tier Application Using Storage Tables, Queues, and Blobs.
Subscribe to:
Posts
(
Atom
)
No comments :
Post a Comment