php - 我需要用 html 按钮(nginx)启动一个 php

标签 php linux bash ubuntu nginx

nginx版本:nginx/1.18.0(Ubuntu 20)

PHP 7.4.3 (cli) (built: Feb 24 2022 14:55:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
我在 html 中创建了一个简单的页面,用于在 php 中使用按钮执行脚本。
这是我的html:
<html>
        <head>
        </head>

        <body>
hello

                <form action="path-of-myphp.php" method="post">
                        <input type="submit" name="backupMySql" value="Backup"/>
                </form>

        </body>

</html>
这里是我的 php
<?php
   echo "Hello";
?>
这是我的 nginx 配置
server {
    server_name  mysite.com;
    location / {
        proxy_pass         https://localhost:5003;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
     location ~ \.(php)$ {
        include /etc/nginx/fastcgi.conf;
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }




    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = mysite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name  mysite.com;
    listen 80;
    return 404; # managed by Certbot


}
我正确地看到了这个按钮,但是当我点击它时,我被重定向到另一个 url,这个 url 是 www.mysite.com/path-of-myphp.php
error nginx
我不明白为什么我的 nginx 不能执行这个简单的 php,但通过 shell 我可以执行所有..
有人有提示吗?
非常感谢

最佳答案

nginx 错误是 404 not found 错误,这意味着 nginx 找不到您的文件。
由于您的 nginx 配置,您的网站根目录位于/var/www/html 中,因此请确保您的 php 文件位于此目录中:

/var/www/html/path-of-myphp.php
请查看您的 php 文件的权限。它必须由 www-data 用户读取
chown (your user or www-data):www-data /var/www/html/path-of-myphp.php
chmod 755 /var/www/html/path-of-myphp.php
这样,www-data 用户至少拥有该组的读取和执行权限。

关于php - 我需要用 html 按钮(nginx)启动一个 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71329025/

相关文章:

linux - 拆分大型 gz 文件同时保留行

linux - 如何在linux控制台上查看两个对话框?同时运行?

bash - 如何获取命令的退出代码而不是 xterm?

php - Codeigniter 如何避免重复显示一对多关系

php - PayPal Sandbox Classic API Express Checkout NVP 内部服务器错误 (500)

php - Ubuntu Server 无法在 PHP 中创建目录

linux - Kafka 连接 - 无法连接到本地主机端口 8083 : Connection refused

javascript - 如何使用 php 将 id 动态传递给弹出窗口

php - 在指定时间后更新 mySQL 行(PHP、MySQL)

linux - 如何删除包含特定文件但不包含其他文件的所有子文件夹