Home Backend Development Golang golang deploy iis

golang deploy iis

May 27, 2023 pm 12:38 PM

With the gradual popularity of Golang in Web development, more and more developers are beginning to use Golang to build Web applications. When deploying Golang applications, many people are accustomed to using Linux servers, but for users using Windows servers, how to deploy Golang applications on IIS? This article will introduce how to deploy Golang applications on IIS.

Step 1: Install Golang

First, you need to install Golang on the Windows server. You can download the latest Golang installer from the official website https://golang.org/dl/, and then follow the prompts to install it.

After the installation is complete, you need to add Golang’s bin directory to the system’s PATH environment variable.

Step 2: Create a simple Golang application

Before deploying the Golang application on IIS, you need to write a simple Golang application for testing. The following is a simple HTTP server program that will return a "Hello, World!" HTTP response:

package main

import (

"fmt"
"net/http"
Copy after login

)

func main() {

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, World!")
})

http.ListenAndServe(":80", nil)
Copy after login

}

This program will listen to port 80 and provide HTTP service on the root path. When accessing this path, the server will return a "Hello , World!” response.

Save the above code as a .go file and use the following command to compile the program:

go build .go

Where, is The name of the file you saved.

Run the program:

./

If everything goes well, the program will display the "Hello, World!" message.

Step 3: Install IIS

In order to run Golang applications on IIS, you first need to install IIS. You can use Windows Server Manager to install IIS. The specific steps are as follows:

Open Windows Server Manager

Select the "Roles and Features" option

In the "Server Roles" option Select the "Web Server (IIS)" option

Select the "Web Server" and "ASP.NET 4.5" options in the "Web Server (IIS)" option

Click the "Install" button , wait for the IIS installation to complete

Once the installation is complete, you can verify whether IIS was installed successfully by entering the server IP address in the browser.

Step 4: Deploy the Golang application on IIS as a CGI script

One way to run the Golang application on IIS is to deploy it on IIS as a CGI script, specifically The steps are as follows:

Create a new website or application pool

Open IIS Manager, select the "Sites" or "Application Pools" option, and then click "Add Website" or "Add Application Pool" button.

Configure the website or application pool

Enter the name, path and other information in the "Add Website" or "Add Application Pool" dialog box. If you are creating a website, you need to specify the root directory of the website and the bound IP address and port; if you are creating an application pool, you need to specify the .NET version used, authentication method and other information.

Deploy the Golang application as a CGI script

Create a new directory and place the compiled Golang application in this directory. Create a web.config file in this directory, which contains information about how IIS runs CGI scripts. You can use the following web.config as a reference:


<system.webServer>
    <handlers>
        <add name="CGI for Golang" path="*.go" verb="*" modules="CgiModule" scriptProcessor="<path to cgi-bin>go.exe" resourceType="Unspecified" />
    </handlers>
</system.webServer>
Copy after login

< /configuration>

Among them, is the bin directory of Golang.

Click the website or application pool created in IIS Manager, select the "Add Virtual Directory" option in the "Actions" box on the right, and specify the path to the directory created in the previous step.

Test Application

Open the browser, enter the IP address and port of the website, and you can see the response of "Hello, World!"

Step Five: Deploy the Golang application on IIS using ISAPI

Compared with deploying the Golang application on IIS as a CGI script, deploying it on IIS using ISAPI can Improve performance and security. The specific steps are as follows:

Download and install Go-ISAPI

You can download the latest version of Go-ISAPI from https://github.com/Zer0xFF/goisapi and follow the README.md file Install according to the instructions in .

Create a website or application pool on IIS

Similarly, open IIS Manager, select "Sites" or "Application Pools", and then click "Add Website" or "Add Application Pool" button.

Configure the website or application pool

Similarly, enter the name, path and other information in the "Add Website" or "Add Application Pool" dialog box.

Configure ISAPI Filter

Right-click the created website or application pool, and in "Manage Website" or "Advanced Settings", find "ISAPI Filters" or "ISAPI and CGI Restrictions" ” option and then select the “Add” option to add a new filter. Enter the name and path to the executable file and select the Allow option to allow the filter to run.

Configure ISAPI extension

In IIS Manager, select the "Server Farm" option, then select "ISAPI and CGI" or "Handler Mappings", click the "Add Module Mapping" or "Add Module Mapping" button, a new ISAPI extension will be inserted program. Enter the name, path, and command line parameters, then click OK to save.

Test Application

Open the browser, enter the IP address and port of the website, and you can see the response of "Hello, World!"

Conclusion

This article introduces how to deploy Golang applications to IIS. Golang applications can be easily deployed to IIS using CGI scripts and using ISAPI. If you are using a Windows server and want to leverage Golang to build a web application, please follow the steps above to try deploying your Golang application.

The above is the detailed content of golang deploy iis. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Golang and C  : Concurrency vs. Raw Speed Golang and C : Concurrency vs. Raw Speed Apr 21, 2025 am 12:16 AM

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Getting Started with Go: A Beginner's Guide Getting Started with Go: A Beginner's Guide Apr 26, 2025 am 12:21 AM

Goisidealforbeginnersandsuitableforcloudandnetworkservicesduetoitssimplicity,efficiency,andconcurrencyfeatures.1)InstallGofromtheofficialwebsiteandverifywith'goversion'.2)Createandrunyourfirstprogramwith'gorunhello.go'.3)Exploreconcurrencyusinggorout

Golang vs. C  : Performance and Speed Comparison Golang vs. C : Performance and Speed Comparison Apr 21, 2025 am 12:13 AM

Golang is suitable for rapid development and concurrent scenarios, and C is suitable for scenarios where extreme performance and low-level control are required. 1) Golang improves performance through garbage collection and concurrency mechanisms, and is suitable for high-concurrency Web service development. 2) C achieves the ultimate performance through manual memory management and compiler optimization, and is suitable for embedded system development.

Golang vs. Python: Key Differences and Similarities Golang vs. Python: Key Differences and Similarities Apr 17, 2025 am 12:15 AM

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

Golang and C  : The Trade-offs in Performance Golang and C : The Trade-offs in Performance Apr 17, 2025 am 12:18 AM

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.

The Performance Race: Golang vs. C The Performance Race: Golang vs. C Apr 16, 2025 am 12:07 AM

Golang and C each have their own advantages in performance competitions: 1) Golang is suitable for high concurrency and rapid development, and 2) C provides higher performance and fine-grained control. The selection should be based on project requirements and team technology stack.

Golang vs. Python: The Pros and Cons Golang vs. Python: The Pros and Cons Apr 21, 2025 am 12:17 AM

Golangisidealforbuildingscalablesystemsduetoitsefficiencyandconcurrency,whilePythonexcelsinquickscriptinganddataanalysisduetoitssimplicityandvastecosystem.Golang'sdesignencouragesclean,readablecodeanditsgoroutinesenableefficientconcurrentoperations,t

See all articles