Skip to content
Follow
Ubuntu Linux

Enable Nginx FastCGI on Ubuntu 24.04

Richard
Written by
Richard
Feb 20, 2025 Updated Sep 15, 2026 3 min read
Enable Nginx FastCGI on Ubuntu 24.04
Enable Nginx FastCGI on Ubuntu 24.04

Nginx FastCGI on Ubuntu 24.04 links your web server to a background program called PHP-FPM so your site loads much faster. This bridge keeps PHP ready to run pages instantly instead of starting a new process for every single click, which stops your server from slowing down when lots of people visit at once.

Advertisement

You need root access to your server and a basic text editor to set it up.

⚡ Quick Answer

Install fcgiwrap with `sudo apt install fcgiwrap`. Configure Nginx by creating `/etc/nginx/fcgiwrap.conf` and including it in your server block. Reload Nginx with `sudo systemctl reload nginx`.

Advertisement

Install FastCGI

Installing FastCGI on Ubuntu 24.04 requires the fcgiwrap package, which allows Nginx FastCGI to run CGI scripts properly. Open your terminal and run sudo apt install fcgiwrap to download and set up the package. Once the installation finishes, you can set up a dedicated folder for your scripts.

🐧Bash / Shell
sudo apt install fcgiwrap

After installing the FastCGI package, we’ll define a location to store our CGI scripts. We’ll create a new /cgi-bin folder in the Nginx root directory for this post.

The URL to the CGI scripts directory will be [/var/www/cgi-bin/].

First, create the CGI directory by running the command below. Then, adjust the directory permissions as needed.

Advertisement
🐧Bash / Shell
sudo mkdir /var/www/cgi-bin
sudo chmod 755 /var/www/cgi-bin

Next, run the command below to create an Nginx configuration file and define our CGI script location and other settings.

🐧Bash / Shell
sudo nano /etc/nginx/fcgiwrap.conf

Then, copy the block below, paste it into the file, and save.

💻Code
location /cgi-bin/ {
gzip off;
root /var/www;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
📝Good to KnowAfter creating the FastCGI config above, include it in your Nginx server block.

We'll use the default server block for this post, but you can create new ones.

Open Nginx default server block.

Advertisement
🐧Bash / Shell
sudo nano /etc/nginx/sites-available/default
📝Good to KnowThen, include the configuration file created above in the server {} section.
💻Code
server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.html index.htm index.nginx-debian.html;

server_name example.com;

include fcgiwrap.conf;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
............
............

Save and exit the file.

Next, enable FastCGI and reload Nginx services by running the command below.

🐧Bash / Shell
sudo  systemctl enable fcgiwrap
sudo systemctl reload nginx

Test Apache CGI execution

Testing script execution for Nginx FastCGI on Ubuntu 24.04 involves creating a simple test script to confirm your server reads CGI files correctly. Create a new file named index.cgi inside your cgi-bin folder using a text editor, add a basic print statement, and load it in your browser.

Advertisement

Run the command below to create a blank CGI index file.

🐧Bash / Shell
sudo nano /var/www/cgi-bin/index.cgi

Copy the script below, paste it into the file, and save.

💻Code
#!/usr/bin/python3

print("Content-type: text/htmln")
print("<html>n<body>")
print("<p style="width: 100%; font-size: 60px; font-weight: bold; text-align: center;">")
print("CGI is Enabled!!!")
print("</p>")
print("</body>n</html>")

Make the file executable by running the command below.

🐧Bash / Shell
sudo chmod 705 /var/www/cgi-bin/index.cgi

Now, open your browser and browse the script.

Advertisement

http://example.com/cgi-bin/index.cgi

Apache CGI enabled
Apache CGI enabled

That should do it!

Conclusion:

  • Configuring Nginx to run CGI scripts on Ubuntu 24.04 enhances the server’s capability to deliver dynamic web content.
  • FastCGI plays a crucial role in handling CGI requests efficiently and effectively.
  • Setting up the /cgi-bin directory allows for organized management of your CGI scripts.
  • Testing the configuration through a simple Python script ensures the setup works correctly.
  • Overall, this configuration opens up possibilities for interactive web features, improving user experience on your website.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
How to Setup WordPress Nginx Cloudflare Ubuntu Fast
CMS How to Setup WordPress Nginx Cloudflare Ubuntu Fast
Change Power Button Behavior in Ubuntu Linux
Ubuntu Linux Change Power Button Behavior in Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *