Would you like to learn how to install Nginx and enable the use of GO CGIs on a computer running Ubuntu Linux? In this tutorial, we are going to show you how to enable the CGI feature and enable GO scripts to run on the Nginx server.
• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0
• GO 1.14.16
Equipment list
The following section presents the list of equipment used to create this tutorial.
As an Amazon Associate, I earn from qualifying purchases.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial Ubuntu – Golang CGI on Nginx
Install the Nginx server and the Fcgiwrap package.
Create a configuration file for the CGI gateway.
Here is the file content.
Create a directory to store the CGI files.
Edit the Nginx configuration file for the default website.
Insert the following line in the area named SERVER.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Nginx service.
Download and install the GO package.
The GOLANG software was installed under the /usr/local folder.
In order to work properly, the GO software expect the system to have a set of environment variables.
Let’s create a file to automate the required environment variables configuration.
Here is the file content.
Reboot your computer.
Verify if the required environment variables were created automatically.
Here is the correct output:
As an example, let’s create a GO script.
Here is the file content.
Build the GO script and move it to the Nginx’s CGI directory.
Access the Nginx’s CGI directory.
Change the file permission.
Open your browser and enter the IP address of your web server plus /cgi-bin/test.go.
In our example, the following URL was entered in the Browser:
• http://172.31.8.195/cgi-bin/test.go
The GO script should display the following message.
Congratulations! You are now able to use the GO as CGI.