search

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"

)

func main() {

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

http.ListenAndServe(":80", nil)

}

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>

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
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
Mastering Go Strings: A Deep Dive into the 'strings' PackageMastering Go Strings: A Deep Dive into the 'strings' PackageMay 12, 2025 am 12:05 AM

You should care about the "strings" package in Go because it provides tools for handling text data, splicing from basic strings to advanced regular expression matching. 1) The "strings" package provides efficient string operations, such as Join functions used to splice strings to avoid performance problems. 2) It contains advanced functions, such as the ContainsAny function, to check whether a string contains a specific character set. 3) The Replace function is used to replace substrings in a string, and attention should be paid to the replacement order and case sensitivity. 4) The Split function can split strings according to the separator and is often used for regular expression processing. 5) Performance needs to be considered when using, such as

'encoding/binary' Package in Go: Your Go-To for Binary Operations'encoding/binary' Package in Go: Your Go-To for Binary OperationsMay 12, 2025 am 12:03 AM

The"encoding/binary"packageinGoisessentialforhandlingbinarydata,offeringtoolsforreadingandwritingbinarydataefficiently.1)Itsupportsbothlittle-endianandbig-endianbyteorders,crucialforcross-systemcompatibility.2)Thepackageallowsworkingwithcus

Go Byte Slice Manipulation Tutorial: Mastering the 'bytes' PackageGo Byte Slice Manipulation Tutorial: Mastering the 'bytes' PackageMay 12, 2025 am 12:02 AM

Mastering the bytes package in Go can help improve the efficiency and elegance of your code. 1) The bytes package is crucial for parsing binary data, processing network protocols, and memory management. 2) Use bytes.Buffer to gradually build byte slices. 3) The bytes package provides the functions of searching, replacing and segmenting byte slices. 4) The bytes.Reader type is suitable for reading data from byte slices, especially in I/O operations. 5) The bytes package works in collaboration with Go's garbage collector, improving the efficiency of big data processing.

How do you use the 'strings' package to manipulate strings in Go?How do you use the 'strings' package to manipulate strings in Go?May 12, 2025 am 12:01 AM

You can use the "strings" package in Go to manipulate strings. 1) Use strings.TrimSpace to remove whitespace characters at both ends of the string. 2) Use strings.Split to split the string into slices according to the specified delimiter. 3) Merge string slices into one string through strings.Join. 4) Use strings.Contains to check whether the string contains a specific substring. 5) Use strings.ReplaceAll to perform global replacement. Pay attention to performance and potential pitfalls when using it.

How to use the 'bytes' package to manipulate byte slices in Go (step by step)How to use the 'bytes' package to manipulate byte slices in Go (step by step)May 12, 2025 am 12:01 AM

ThebytespackageinGoishighlyeffectiveforbyteslicemanipulation,offeringfunctionsforsearching,splitting,joining,andbuffering.1)Usebytes.Containstosearchforbytesequences.2)bytes.Splithelpsbreakdownbyteslicesusingdelimiters.3)bytes.Joinreconstructsbytesli

GO bytes package: What are the alternatives?GO bytes package: What are the alternatives?May 11, 2025 am 12:11 AM

ThealternativestoGo'sbytespackageincludethestringspackage,bufiopackage,andcustomstructs.1)Thestringspackagecanbeusedforbytemanipulationbyconvertingbytestostringsandback.2)Thebufiopackageisidealforhandlinglargestreamsofbytedataefficiently.3)Customstru

Manipulating Byte Slices in Go: The Power of the 'bytes' PackageManipulating Byte Slices in Go: The Power of the 'bytes' PackageMay 11, 2025 am 12:09 AM

The"bytes"packageinGoisessentialforefficientlymanipulatingbyteslices,crucialforbinarydata,networkprotocols,andfileI/O.ItoffersfunctionslikeIndexforsearching,Bufferforhandlinglargedatasets,Readerforsimulatingstreamreading,andJoinforefficient

Go Strings Package: A Comprehensive Guide to String ManipulationGo Strings Package: A Comprehensive Guide to String ManipulationMay 11, 2025 am 12:08 AM

Go'sstringspackageiscrucialforefficientstringmanipulation,offeringtoolslikestrings.Split(),strings.Join(),strings.ReplaceAll(),andstrings.Contains().1)strings.Split()dividesastringintosubstrings;2)strings.Join()combinesslicesintoastring;3)strings.Rep

See all articles

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!