我需要使用 htm 按钮(ngninx)启动 php

发布于 2025-01-11 09:00:22 字数 2284 浏览 0 评论 0原文

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


}

我正确地看到了按钮,但是当我点击它时,我被重定向到另一个网址,这个网址是 www.mysite.com/path-of-myphp.php

error nginx

我不明白为什么我的nginx不能执行这个简单的php,同时通过shell我可以执行所有.. 有人有提示吗? 非常感谢

nginx version: 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

I've created a simple page in html, for execute a script in php with a button.
Here my html:

<html>
        <head>
        </head>

        <body>
hello

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

        </body>

</html>

and here my php

<?php
   echo "Hello";
?>

Here my nginx config

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


}

I see correctly the button, but when i click on it, i am redirected to another url, and this url is www.mysite.com/path-of-myphp.php

error nginx

I don't undestand why my nginx can't execute this simple php, meanwile by shell i can execute all..
Anyone have tips?
thank very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2025-01-18 09:00:23

nginx 错误是 404 not find 错误,这意味着 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 用户至少具有该组的读取和执行权限。

The nginx error is a 404 not found error and it means that nginx can't find your file.
Due to your nginx configuration your website root is in /var/www/html, so make sure that your php file is inside this directory:

/var/www/html/path-of-myphp.php

Please take a look also to the permissions of your php file. It has to be readable by www-data user

chown (your user or www-data):www-data /var/www/html/path-of-myphp.php
chmod 755 /var/www/html/path-of-myphp.php

In this way the www-data user has at least read and execution permissions by the group.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文