This article explains how to install fcgiwrap for Nginx on Ubuntu 20.04 Linux. Configure Nginx and write your first CGI script.

seen from Netherlands

seen from Malaysia

seen from Hungary
seen from Türkiye

seen from United Kingdom
seen from Japan

seen from United States

seen from Sweden
seen from China

seen from Italy

seen from Italy

seen from Germany

seen from Italy
seen from Spain

seen from Italy
seen from China
seen from China

seen from Italy
seen from China

seen from Ireland
This article explains how to install fcgiwrap for Nginx on Ubuntu 20.04 Linux. Configure Nginx and write your first CGI script.
nginx + fcgiwrap (spawn-fcgi) + Mailgraph
nginx + fcgiwrap (spawn-fcgi) + Mailgraph
手上還是有固定一台機器是自己架設 Postfix 管理郵件系統,所以還是想跑個 Mailgraph 看一下有多少量在上面跑…
不過因為 Mailgraph 的 web interface 只有 CGI 界面,但 nginx 不支援 CGI,所以需要找個工具透過 nginx 支援的 FastCGI 轉換進去。
概念與設定都不算太難,但是得把工具找齊才會動 (這段花了不少時間),所以記錄一下怎麼做,以後找比較好找資料。
首先先裝 Mailgraph 與 fcgiwrap:
sudo apt install -y fcgiwrap mailgraph
這兩個程式預設都會跑起來。如果沒有的話自己用 sudo service fcgiwrap status 與 sudo service mailgraph status。接下來在 nginx 的找個 virtual host 裡面這樣設:
View On WordPress
Instalar un servidor Lighttpd en CentOS 7
Instalar un servidor Lighttpd en CentOS 7. Lighttpd es un servidor web de código abierto, especialmente diseñado para operar en entornos críticos a una alta velocidad. A pesar de su extrema optimización, cumple el estándar de ser seguro y flexible. Un servidor Lighttpd de alta velocidad, ofrece una mejoría de rendimiento considerable (con el mismo hardware), en comparación con otros servidores web. Es compatible con las interfaces FastCGI, SCGI y CGI, por tanto es capaz de ejecutar aplicaciones web escritas en cualquier lenguaje de programación. Destacamos que el FastCGI de Lighttpd, se puede configurar para que admita PHP con caché de códigos operacionales, también recibe soporte por parte de las comunidades de Perl, Python y Ruby. Antes de comenzar el articulo, debo indicarte, que no existen paneles de control web (100% compatibles), que manejen este tipo de servidores. El trabajo debe ser manual.
Instalar un servidor Lighttpd en CentOS 7
Como es habitual lo primero que haremos es actualizar nuestro sistema. yum update Habilitamos el repositorio Epel, y actualizamos de nuevo. yum -y install epel-release yum -y update No es necesario que reinicies el sistema, directamente vamos a instalar lighttpd. yum install lighttpd Iniciamos y habilitamos el servicio. systemctl start lighttpd systemctl enable lighttpd Ahora puedes verificar el servicio. systemctl status lighttpd Obtendrás un resultado similar a este... ● lighttpd.service - Lightning Fast Webserver With Light System Requirements Loaded: loaded (/usr/lib/systemd/system/lighttpd.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2019-09-02 12:52:11 CDT; 2s Main PID: 11445 (lighttpd) CGroup: /system.slice/lighttpd.service └─11445 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf Si no se ejecuta correctamente, editamos el archivo de configuración y anulamos la IPv6. nano /etc/lighttpd/lighttpd.conf En la linea "server.use-ipv6", sustituyes enable por disable. Guarda el archivo y cierra el editor. Reiniciamos: systemctl restart lighttpd Al insertar la ip del server en tu navegador web preferido, veras la pagina por defecto de Lighttpd. Instalar MariaDB Si en tu caso necesitas una base de datos, instalamos MariaDB. yum -y install mariadb mariadb-server Iniciamos y habilitamos el servicio. systemctl start mariadb.service systemctl enable mariadb.service Instalar PHP y PHP-FPM con FastCGI en Lighttpd Para instalar PHP junto con las extensiones necesarias, ejecuta el siguiente comando (si necesitas otra versión php, recuerda instalar antes el repositorio remi): yum -y install php php-mysqlnd php-pdo php-gd php-mbstring Habilitamos el soporte de PHP-FPM y FastCGI con Lighttpd. yum -y install php-fpm lighttpd-fastcgi Nos falta editar el archivo de configuración de PHP-FM. nano /etc/php-fpm.d/www.conf Modifica el archivo como en el ejemplo: ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache Choosed to be able to access some dir as httpd user = lighttpd ; RPM: Keep a group allowed to write in log dir. group = lighttpd Guarda el archivo, y cierra el editor. Iniciamos y habilitamos el servicio PHP-FPM. systemctl start php-fpm.service systemctl enable php-fpm.service Verificamos: systemctl status php-fpm.service ejemplo de salida correcta... ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2019-09-02 13:30:09 CDT; 10s Main PID: 11571 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec" CGroup: /system.slice/php-fpm.service Ya lo tenemos listo. Espero que este articulo te sea de utilidad, puedes ayudarnos a mantener el servidor con una donación (paypal), o también colaborar con el simple gesto de compartir nuestros artículos en tu sitio web, blog, foro o redes sociales. Read the full article
Fixed: Apache 2.4 service failed to start when disabling FastCGI with default PHP set as 7.3 There was an issue when having default PHP version set as PHP 7.3 and FastCGI option disabled from Apache Settings page, the Apache 2.4 service failed to start.
當 Daemon 死掉時自動重新跑起...
當 Daemon 死掉時自動重新跑起…
以前確保 daemon 掛掉時會重新跑起來大概有幾個方式,像是用 Monit 顧,然後再用 /etc/inittab 確保 Monit 不會掛掉…
在 systemd 的年代,因為 systemd 已經被保護起來,而重跑這個功能在 systemd 裡就有支援,不需要用 Monit 這類程式了。
在 manual 裡搜尋 restart 可以看到幾個參數:
Restart=
RestartForceExitStatus=
RestartPreventExitStatus=
RestartSec=
這次是遇到 SmokePing 的 FastCGI daemon 每隔幾天會自己死掉,導致 nginx 丟出 503 然後被 UptimeRobot 偵測到而拋出警告。
但這個問題只有在一台伺服器會發生,而 log 裡也沒翻到可以繼續 debug 的錯誤訊息,試著猜測一些情境去搜尋引擎找也沒翻到……
View On WordPress
在 nginx 環境中把 Trac 裝到子目錄下的設法
在 nginx 環境中把 Trac 裝到子目錄下的設法
以前的「Nginx + FastCGI + Trac」提到給的範例是把 Trac 裝在 / 下的方法。如果是裝在 /trac 或是其他路徑時就需要修改了。 一開始試著改會出現這樣的錯誤: No handler matched request to /trac/report/7 然後研究調整後,發現 Trac 純粹是吃 FastCGI 給的參數去判斷要怎麼處理 url routing,在 trac.ini 內 url 相關參數主要還是用在其他地方… (像是信件通知時用的 url) 首先是把檔案簡化,這是 2016 年寫的: location / { auth_basic "trac realm"; auth_basic_user_file /srv/domain.example.com/.htpasswd; include fastcgi.conf; fastcgi_param…
View On WordPress
nginx fastcgi cache
Nginx can cache the results of FastCGI, uWSGI proxied requests and even the results of load balanced requests (requests sent "upstream"). This means we can cache the results of requests to our dynamic applications.
If we use Nginx to cache the results of a FastCGI process, we can think of the FastCGI process as the Origin Server and Nginx as the Cache Server.
Here's an example vhost config utilising fastcgi proxy cache:
fastcgi_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=cache:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; server { # Boilerplate omitted set $no_cache 0; log_format caching '$remote_addr $host $remote_user [$time_local] ' '"$request" $status $body_bytes_sent $upstream_cache_status ' '"$http_referer" "$http_user_agent" $request_time $upstream_response_time $pipe'; access_log /var/log/nginx/cache.log caching; # Example: Don't cache admin area if ($request_uri ~* "/(admin/)") { set $no_cache 1; } location ~ ^/(index)\.php(/|$) { fastcgi_cache cache; fastcgi_cache_valid 200 60m; # Only cache 200 responses, cache for 60 minutes fastcgi_cache_methods GET HEAD; # Only GET and HEAD methods apply add_header X-Fastcgi-Cache $upstream_cache_status; fastcgi_cache_bypass $no_cache; # Don't pull from cache based on $no_cache fastcgi_no_cache $no_cache; # Don't save to cache based on $no_cache # Regular PHP-FPM stuff: include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; } }
You can tell if it's working if there's stuff inside /var/lib/nginx/cache. You'll also see response headers for items matched in your location block:
$ curl -X GET -I mygroovysite.com/index.php X-Fastcgi-Cache: MISS $ curl -X GET -I mygroovysite.com/index.php X-Fastcgi-Cache: HIT $ curl -X GET -I mygroovysite.com/admin X-Fastcgi-Cache: BYPASS
If you're doing some load testing, to determine the efficiency of your shiny new cache, you can get a summary with:
awk '{print $11}' /var/log/nginx/cache.log | sort | uniq -c 2327 HIT 536 MISS
I like this last command best ;)
How to install PHP 7.x as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 and 9 This tutorial shows how to install PHP 7.x as a PHP-FPM and a FastCGI version on a Debian Jessie or Stretch server from the Debian PHP Package maintainers site directly. Read more: How to install PHP 7.x as PHP-FPM & FastCGI for ISPConfig 3.1 with apt on Debian 8 and 9