Hi,
i just moved my dyndns service from my apache2 server to my new nginx machine. While the service was working good on apache it didn´t on nginx.
The Fritzbox connects to my dyndns service via this link
http://dyn.myserver.co/myscript.php?pass=mypassword&meineip=<ipaddr>
Thats the script (myscript.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");} }
?>
And here is my config for dyn.myserver.co on 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;
}
}
The IP which is written in my_IP.txt is copied to the DNS Server by cronjob. That is working. For example: On my apache server i called the dyndns URL (http://dyn.myserver.co/myscript.php) and was redirected to the IP which was filled in my_IP.txt. On nginx it just shows me the content of myscript.php.
I think it´s a problem with the nginx config. Can anybody help me?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
I already tried
try_files $uri $uri/ =404;
and its not working. The skript is shown as plain text while calling the URL…I´m wondering because any of the wordpress sites are working good.
@hansen Thats the output:
Ah ok no wordpress is running on another site not on dyn.
@r0g Please run the following to list all site configurations:
If you’re using WordPress too on the same site, then the
try_files
should be this:Hi @hansen
no i´m running nginx on a dedicated root server. Thank you i´ll try that.
Hi @r0g
Are you using DigitalOcean droplets? Or are you running Nginx on your home server?
Change this line in the Nginx config and restart Nginx
service nginx restart
:It should be change to this (I’m guessing you’re running WordPress too?):
If you don’t run WordPress or something like that, then change it to this: