Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

Monday, January 29, 2018

Automatically Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2.0

In a previous article I covered the installation URL Rewrite 2.0 for IIS 7. This is a plug-in for IIS 7 that allows you to manipulate URL’s.
URL Rewrite has a GUI to allow you to enter rules within IIS 7; in the background all this does is edit the web.config file of the site. I will show you how to create a rule both ways.
In the following example we will redirect HTTP to HTTPs using URL Rewrite. You will need the following items completed in order for this to work correctly.
– SSL Certificate for site installed in IIS.
– Site properly installed and configured for SSL (site set up and binding in IIS configured).
– URL Rewrite 2.0 is installed on the sever.

GUI Version

– Select the website you wish to configure
– In the “Features View” panel, double click URL Rewrite
You will notice there are currently no rules configured for this site. Click “Add Rules…” in the Actions menu to the right of the “Features View” panel
Use the default “Blank rule” and press “OK”.
When editing a rule there are the “Name” field and 4 configuration pull down boxes.
– Enter “Redirect to HTTPS” in the name field.
– Next we will configure the first configuration pull down box called “Match URL”, on the right side of “Match URL” press the down arrow to expand the box.
Within the “Match URL” configuration box we will set the following settings:
Requested URL: Matches the Pattern
Using: Regular Expressions
Pattern: (.*)
We can now edit the next configuration pull down box which is “Conditions”, Press “Add…” to add a new condition to the configuration.
We will configure the condition with the following settings:
Condition Input: {HTTPS}
Check if input string: Matches the Pattern
Pattern: ^OFF$
Press “OK”
You should see your condition in the list of conditions.
For this setting we do not need to configure the “Server Variables” pull down box. Continue onto the “Action” configuration box and pull down the box by selecting the arrow on the right. We will configure the following settings for the “Action” configuration:
Action Type: Redirect
Redirect URLhttps://{HTTP_HOST}/{R:1}
Redirect Type: See Other (303)
Press “Apply” then press “Back to Rules”
You should now see the rule configured on the main screen of the URL Rewrite module.
Test your site, it should now redirect from HTTP to HTTPS.
If we exam the web.config file we can see where the rule was entered. If we entered the rule directly into the web.config file it would show up in the GUI.
Web.Config Rule
You can also edit the web.config file of the site directly and you will be able to see the rule in the GUI. You will need to enter the following within the <system.webServer> </system.webServer> elements.
?
1
2
3
4
5
6
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
When implementing this solution you need to make sure to use relative paths for all references on your page because there is a possibility you will get a warning asking you if you want to display secure and insecure items. For example, if you have a logo on your page and the URL to this logo is http://domain/images/logo.jpg, do not use the whole path because including the http:// will hard code this image to use http and not https. Instead use /images/logo.jpg.
Source : http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

Tuesday, April 9, 2013

Install IIS 7.5 PHP & FastCGI for PHP on Windows 7


Why install IIS?
Obviously you want to design web sites on your local computer and test them before uploading to your web server.

Why install FastCGI and not ISAPI?
Up until php version 5.3 most web developers using php installed ISAPI
From php version 5.3 on ISAPI is not longer supported.
The alternative is to use FastCGI
Although there are many web sites complaining about this change ISAPI works well for a website with 0-20 users,
however FastCGI runs much faster under a heavy user load and equally as well with smaller loads.

This guide has been updated and rewritten as the easiest way to successfully Configure IIS 7.5 to work with FastCGI and PHP on Windows 7 is to use
Microsoft Web Platform Installer 2.0 from http://www.microsoft.com/web/Downloads/platform.aspx
Why?
The installer does all the hard work
No more downloading PHP then configuring the php.ini file
No more going into your Internet Information Services (IIS) Manager and adding a Handler Mapping FastCGI Module
No more going into your System Properties and setting up your Environmental Variables
No more spending endless hours surfing around looking for solutions that help you get it all working (it rarely happens first time)
Microsoft have done all the hard time consuming work for a change - miracles do happen.

NOTE: This install was completed on Windows 7 Ultimate 64 bit and works for 32 bit systems.

STEP 1

Open the site and click on Download It Now
Download it to your chosen folder


Step 2

Open the folder you downloaded to & double click wpilauncher


Step 3

Click Run


Step 4

Wait

Step 5

Select to programs you wish to install
In this case click on Web Platform in left column
Go to Frameworks and Runtimes then click Customize

 

Step 6

Now just tick the boxes under PHP
Click Install


Step 7

Now wait while Web Platform Installation downloads, installs & configures your files


Step 8

Success! - click Finish


Step 9

Now to check the install - go Start then Run
If Run does not appear on menu simply type Run in 'Search progams and files' box


Step 10

Type cmd



Step 11

The screen below appears - after C:\Users\User> type cd c:\PHP
Hit 'Enter' on keyboard



Step 12

After c:\PHP> type PHP -info
Hit 'Enter' on keyboard
Watch the screen



Step 13

The screen below is the bottom of the file


Step 14

Next test
Open Notepad and type <?php phpinfo();?>


Step 15

Save (using Save As...) the file in C:\inetpub\wwwroot as info.php


Step 16

Save php.info file here


Step 17

Close open folders
Open browser and type http://localhost/info.php
The file below should come up on the screen.
Success!
Note: This screen can provide a lot of information about your setup that may come in handy in the future.

Congratulations! - you have now Installed, Configured & Tested IIS 7.5 & PHP & FastCGI

The next step is using databases such as MySQL and Interfacing it with PHPMyAdmin, links below

NOTE: This installation does NOT enable mcrypt by default - see link below
In PHPMyAdmin you will receive the following
PHPMyAdmin Error "Cannot load mcrypt extension. Please check your PHP configuration"

Monday, December 12, 2011

ASP.NET & Visual Studio 2005,2008 - Publish Web Site

ASP.NET & Visual Studio 2005,2008 - Publish Web Site การนำโปรเจคไปใช้งานจริงบน Web Site หรือ Web Server หลังจากที่เราได้พัฒนาโปรแกรมจนเสร็จสิ้นแล้วและต้องการนำไปใช้งานจริง เราจะสังเกตุว่าใน Version 2005 และVersion 2008 ทุก ๆ ครั้งที่เราจะทำการ Run โปรแกรมจะไม่มีการ Build ให้อัตโนมัติเหมือนกับ 2003 เฉพาะฉะนั้น เราจะต้องทำการ Build ด้วยตัวเองครับ ประโยชน์ของการ Build ก็เปรียบเสมือนการบรรจุ Package โปรแกรมให้พร้อมใช้งานได้ในทันที ข้อดีก็คือ โปรแกรมจะทำการอ่าน Package ที่ได้จากการ Build แทนที่จะอ่านจากตัว Source Code ซึ่งต่อไปนี้ .vb หรือ .cs ก็จะไม่จำเป็นอีกต่อไป Source Code ต่าง ๆ ที่เราได้เขียนขึ้นมานั้นก็สามารถป้องกันการ Copy หรือการนำไปใช้ที่อื่น ๆ ได้อีก


เริ่มการ Build


Visual Studio 2005,2008

คลิกขวาที่ Project เลือก Publish Web Site


Visual Studio 2005,2008

ระบุโฟเดอร์ปลายทาง

Visual Studio 2005,2008

ได้ Package ที่พร้อมใช้หลังจากการ Build ซึ่งตอนนี้มีโฟเดอร์ bin อยู่แล้วครับ และไฟล์นามสกุล .vb หรือ .cs จะไม่จำเป็นต้องใช้อีกต่อไป 


Visual Studio 2005,2008

.dll ของโปรเจคที่ได้จากการ Build 


http://www.thaicreate.com/asp.net/asp.net-visual-studio-2005-publish-web-site.html

Running multiple versions of the Framework in ASP.NET

Like any good technology, ASP.NET continues to evolve as new versions are released.  But, like anything else, this brings with it a number of considerations. 

Microsoft has done a great job of allowing multiple versions of the framework to run side by side.  Version v1.0, v1.1 and v2.0 can all run together at the same time on the same server.  Each site, or even a vdir (Virtual Directory) within a site can have its own version of the framework installed.  Simply install the framework version on your server and it will be available to you.  The install itself is quite small, for example the v2.0 download is 22MB. 

The Microsoft homepage for the .NET Framework is: 
http://msdn.microsoft.com/netframework/downloads/updates/default.aspx 

There are a couple gotchas to consider with running multiple versions of the framework side by side.  First, let's dig into IIS a bit.  Following is a snapshot of Windows Task Manager on an IIS5 (Windows 2000) server: 

aspnet_wp.exe_iis5  

Notice the 3 processes called aspnet_wp.exe.  There is one per version of the framework. (v1.0, v1.1 and v2.0)  If a process for a particular version of the framework doesn't exist, as soon as it's needed, a new process will be spun up.  This allows multiple versions of the framework to live beside each other in IIS5.  No effort, no pain . . . it just works. 

Now consider the following IIS6 (Windows Server 2003) screenshot: 
w3wp.exe_iis6  


Notice that there aren't any aspnet_wp.exe processes anymore, but there are w3wp.exe processes instead.  IIS6 was an impressive upgrade that brought with it some new concepts.  One key new concept is Application Pools.  A system administrator is able to create groups of sites and place each site in its own group.  Whenever a site needs to run, a w3wp.exe process will start for its application pool if it hasn't already started.  This brings with it a number of welcome security, performance and management advantages.  You are now able to specify your own Identity User which can be unique per Application Pool. 

In IIS6, the aspnet_wp.exe process is done away with, and the work that it did is now done within each w3wp.exe process.  This has the same advantages I mentioned previously, but it has one big gotcha!  

You cannot run more than one version of the framework in the same application pool in IIS6. 

While multiple versions of the framework can co-exist on the same server, they can't co-exist in the same process.  If you attempt to run multiple versions of the framework at the same time in the same process, the 2nd version that tries to run will fail with the following error: 

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur. 
You will also receive Event ID 1062 in Event Viewer that says: 

"It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process." 

What to do 

Fortunately, the solution is easy enough.  Simply create a new application pool and move the site that you will be upgrading to that pool.  You can even base it off of the existing one if you don't have the password memorized for the existing one.  This is all done within IIS.  Once you have placed the site or vdir in its own application pool, then you are ready to upgrade to the new framework version. 

I'll cover the different ways to move between different versions of the framework in another blog within the next few days, but the key thing to walk away with now is that multiple versions of the framework cannot co-exist in the same worker process at the same time.  IIS5 didn't have any issue with this, but IIS6 requires that each version be in its own app pool.


ref : http://weblogs.asp.net/owscott/archive/2006/01/26/Running-multiple-versions-of-the-Framework-in-ASP.NET.aspx