我在我的专用根服务器上运行nginx,并有多个WordPress的网站。nginx不执行php文件
此外我想通过PHP脚本更新我的私人IP。为此,我创建了这个PHP文件(myscript.php):
<?php
$pwort = 'mypassword';
$port = ':80';
$dyntxt = "my_IP.txt";
$pworttest = $_GET["pass"];
$IP = $_GET["meineip"];
if (file_exists($dyntxt)){
if($pworttest==$pwort) {
$a = fopen("$dyntxt", "w");
$dynamicip = $_SERVER["REMOTE_ADDR"];
fwrite($a, $IP);
fclose($a);
}
else {
$a = fopen("$dyntxt", "r+");
$dynamicip = fread($a,filesize($dyntxt));
fclose($a);
$url="http://".$dynamicip."".$port;
header("Location: $url");
}
}
?>
这里是我的配置为dyn.myserver.co上nginx的:
server {
listen 80;
listen [::]:80;
root /var/www/dyn;
index index.php index.html index.htm;
server_name dyn.myserver.co;
location/{
try_files $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/dyn;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这是写在MYIP的IP。通过cronjob将txt复制到DNS服务器。这是行得通的。 例如:在我的apache服务器上,我调用了dyndns URL(http://dyn.myserver.co/myscript.php),并被重定向到填充在myIP.txt中的IP。在nginx上它只显示了myscript.php的内容。
服务PHP5-FPM状态给出:
[email protected]:/etc/php5/fpm/pool.d# service php5-fpm status
● php5-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php5-fpm.service; enabled)
Active: active (running) since Tue 2017-07-11 16:08:54 CEST; 3 days ago
Process: 495 ExecStartPre=/usr/lib/php5/php5-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 613 (php5-fpm)
Status: "Processes active: 0, idle: 3, Requests: 3294, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php5-fpm.service
├─ 613 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
├─ 677 php-fpm: pool www
├─ 1486 php-fpm: pool www
└─23693 php-fpm: pool www
Jul 11 16:08:52 host01 systemd[1]: Starting The PHP FastCGI Process Manager...
Jul 11 16:08:54 host01 systemd[1]: Started The PHP FastCGI Process Manager.
我认为这是与nginx的配置有问题。有谁能够帮助我?
'my_IP.txt'与您的PHP脚本位于同一个文件夹中吗?如果没有,它会给出空白页面,而不是重定向,因为'file_exists($ dyntxt)'是'false' – StefansArya