我需要使用 htm 按钮(ngninx)启动 php
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
我不明白为什么我的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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nginx 错误是 404 not find 错误,这意味着 nginx 找不到您的文件。
由于您的 nginx 配置,您的网站根目录位于 /var/www/html 中,因此请确保您的 php 文件位于此目录中:
另请查看 php 文件的权限。 www-data 用户必须能够读取
这样 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:
Please take a look also to the permissions of your php file. It has to be readable by www-data user
In this way the www-data user has at least read and execution permissions by the group.