我在我的专用根服务器上运行nginx,并且有多个wordpress站点。
此外,我想通过PHP脚本更新我的私有IP。出于这个原因,我创建了这个PHP文件(myscript.php):
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;
}
}
这是我在nginx上的dyn.myserver.co的配置:
root@host01:/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.
通过cronjob将myIP.txt中写入的IP复制到DNS服务器。那很有效。 例如:在我的apache服务器上,我调用了dyndns URL(http://dyn.myserver.co/myscript.php),并被重定向到填充myIP.txt的IP。在nginx上它只显示了myscript.php的内容。
服务php5-fpm状态给出:
$("input").inputmask({
mask: "9999 9999 9999 9999",
placeholder: ""
});
我认为这是nginx配置的问题。有人能帮助我吗?
答案 0 :(得分:0)
将此信息放在网站上可用的文件夹
server {
listen 80;
#listen [::]:80;
root /var/www/dyn;
index index.php index.html index.htm;
server_name dyn.myserver.co;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
然后,您必须将该文件链接到启用站点的文件夹
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
并重新启动nginx服务
答案 1 :(得分:0)
我解决了这个问题...
这是我的scipt:
<?
$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");} }
?>
但必须是:
<?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");} }
?>
非常感谢@StefansArya的努力!