Nginx

php7.4-fpm 不適用於 nginx/1.21.3

  • October 1, 2021

我有一個手動編譯的nginx/1.21.3 w http3 + quic 的實驗設置。

我還成功編譯了一個實驗性curl w http3 實現:

root@domac:~# curl --version
curl 7.80.0-DEV (x86_64-pc-linux-gnu) libcurl/7.80.0-DEV OpenSSL/1.1.1k zlib/1.2.11 ngtcp2/0.1.0-DEV nghttp3/0.1.0-DEV
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTP3 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets
root@domac:~#

但是,當我下載https://domac.alu.hr:8443/test.php時,我收到以下資訊:

mtodorov@domac:~$ curl --http3 https://domac.alu.hr:8443/test.php
<?php var_export($_SERVER)?>
mtodorov@domac:~$

我的 nginx 是:

root@domac:~# nginx -V
nginx version: nginx/1.21.3 (nginx-quic)
built by gcc 8.3.0 (Debian 8.3.0-6)
built with OpenSSL 1.1.1 (compatible; BoringSSL) (running with BoringSSL)
TLS SNI support enabled
configure arguments: --build=nginx-quic --with-debug --add-module=../njs/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/run/lock/subsys/nginx --user=www-data --group=www-data --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_slice_module --with-http_stub_status_module --with-http_v3_module --with-http_quic_module --with-stream_quic_module --with-cc-opt=-I../boringssl/include --with-ld-opt='-L../boringssl/build/ssl -L../boringssl/build/crypto'
root@domac:~#

我的 /etc/nginx/nginx.conf 是:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
error_log  /var/log/nginx/error.log  info;
pid        /var/run/nginx/nginx.pid;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   worker_connections  1024;
}


http {
   include       mime.types;
   default_type  application/octet-stream;
   index         index.php index.html index.htm;

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';

   access_log  /var/log/nginx/access.log  main;

   sendfile        on;
   #tcp_nopush     on;

   #keepalive_timeout  0;
   keepalive_timeout  65;

   #gzip  on;

   server {
       listen       8080;
       server_name  domac.alu.hr;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       root   /srv/www/nginx;

       location / {
       }

       #error_page  404              /404.html;

       # redirect server error pages to the static page /50x.html
       #
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }

       # proxy the PHP scripts to Apache listening on 127.0.0.1:80
       #
       #location ~ \.php$ {
       #    proxy_pass   http://127.0.0.1;
       #}

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
       #
       location ~ [^/]\.php(/|$) {
           # root           /srv/www/nginx;
           fastcgi_split_path_info ^(.+?\.php)(/.*)$;
           # if (!-f $document_root$fastcgi_script_name) {
               # return 404;
           # }

           fastcgi_pass   unix:/var/run/php/php7.3-fpm.sock;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           fastcgi_param  HTTP_PROXY "";
           include        fastcgi_params;
       }

       # deny access to .htaccess files, if Apache's document root
       # concurs with nginx's one
       #
       location ~ /\.ht {
           deny  all;
       }
   }


   # another virtual host using mix of IP-, name-, and port-based configuration
   #
   #server {
   #    listen       8000;
   #    listen       somename:8080;
   #    server_name  somename  alias  another.alias;

   #    location / {
   #        root   html;
   #        index  index.html index.htm;
   #    }
   #}


   # HTTPS server
   #

     server {
           listen 8443 ssl;              # TCP listener for HTTP/1.1
           listen 8443 http3 reuseport;  # UDP listener for QUIC+HTTP/3

           ssl_protocols       TLSv1.3; # QUIC requires TLS 1.3
           ssl_certificate     certs/domac_alu_hr_20201111.pem;
           ssl_certificate_key certs/private/domac_alu_hr_20201111.key;

           add_header Alt-Svc 'h3=":8443"';   # Advertise that HTTP/3 is available
           add_header QUIC-Status $quic;     # Sent when QUIC was used

           root   /srv/www/nginx;

           location / {
           }

           access_log  /var/log/nginx/access-ssl.log  main;
           error_log   /var/log/nginx/error-ssl.log   info;
     }

   # server {
   #     listen       8443 ssl http3 quic;
   #     server_name  localhost;

   #    ssl_certificate      cert.pem;
   #    ssl_certificate_key  cert.key;

   #    ssl_session_cache    shared:SSL:1m;
   #    ssl_session_timeout  5m;

   #    ssl_ciphers  HIGH:!aNULL:!MD5;
   #    ssl_prefer_server_ciphers  on;

   #    location / {
   #        root   html;
   #        index  index.html index.htm;
   #    }
   # }

}

問題似乎是沒有呼叫php7.4-fpm,但是nginx顯示逐字test.php文件,而不是它的執行結果?

在同一台伺服器上,有一個 apache2 守護程序可以很好地與 php7.4-fpm 和 HTTP/2 配合使用,但我想實現 HTTP/3,目前(2021 年 10 月 1 日)不支持 apache2 AFAIK。

非常感謝,我什至嘗試過strace -p <proc>在主 nginx proc 上,但它似乎甚至沒有嘗試打開**/var/run/php/php7.4-fpm.sock** …

我知道這是一個實驗性建構,但我想讓它工作。我以為fastcgi支持可能已經編譯出來了,但是這樣的./configure選項沒有打開。

知道我可能做錯了什麼嗎?

在偵聽埠 8443(您從中訪問它的位置)的伺服器塊中,沒有配置 PHP 處理程序。顯然,您應該為 PHP-FPM 添加它來處理腳本。

使用 8443 埠復製location ~ [^/]\.php(/|$) { .. }到內部。server { }

引用自:https://unix.stackexchange.com/questions/671390