我买了一个新的 VPS,通过 apt 安装了 Ubuntu server 20.04、nginx、php7.4-fpm、MariaDB。
我 scp 上传了我的(在 Ubuntu 20.04 笔记本电脑上运行)PHP 项目。我可以通过 ssh curl 和笔记本电脑上的浏览器看到“感谢您使用 nginx”页面,但是当我尝试使用时dm.mydomain.tld
,两者都返回了注释。请求已登录,access.log
所有权为/var/www/dm
root,与相同/var/www/html
。UFW 已禁用,没有 SELINUX。
如下dm.conf
所示:
server {
listen 443 ssl; #http2 ;
listen [::]:443 ssl; #http2;
root /var/www/dm;
ssl_certificate /etc/ssl/certs/cloudflaresource.pem;
ssl_certificate_key /etc/ssl/private/cloudflaresource.key;
# Add index.php to the list if you are using PHP
index index.php; # index.html index.htm index.nginx-debian.html;
server_name dm.mydomain.tld;
autoindex on;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
ssh 控制台的 curl 输出:
root@VPS:~# curl -vk https://dm.mydomain.tld
* Trying 127.0.0.1:443...
* TCP_NODELAY set
* Connected to dm.mydomain.tld (127.0.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: O=CloudFlare, Inc.; OU=CloudFlare Origin CA; CN=CloudFlare Origin Certificate
* start date: Mar 5 07:31:00 2022 GMT
* expire date: Mar 1 07:31:00 2037 GMT
* issuer: C=US; O=CloudFlare, Inc.; OU=CloudFlare Origin SSL Certificate Authority; L=San Francisco; ST=California
* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x561a6f79e880)
> GET / HTTP/2
> Host: dm.mydomain.tld
> user-agent: curl/7.68.0
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< server: nginx/1.18.0 (Ubuntu)
< date: Sat, 05 Mar 2022 13:58:11 GMT
< content-type: text/html; charset=UTF-8
<
* Connection #0 to host dm.mydomain.tld left intact
您可以看到响应是空的。
此外,这是access.log
入口。
127.0.0.1 - - [05/Mar/2022:15:44:13 +0100] "GET / HTTP/2.0" 200 0 "-" "curl/7.68.0"
更新:我创建了一个 html 文件并对其进行了 curl 操作,运行正常。但对于简单的 php helloworkd,它不起作用。
答案1
/var/run/php/php7.4-fpm.sock
由于问题在重启后出现,所以我检查了 unix 域套接字。 (run ll
in /var/run/php/
)的所有权是www-data
,这不应该是,因为我没有更改它。
所以我猜测它是由 nginx 创建的,因为没有。只需更改 dm.conf 中的条目,一切就都正常了:
/var/run/php/php-fpm.sock
另外,请记住取消注释此行:
include snippets/fastcgi-php.conf;
令我烦恼的是没有报告任何错误。