Question

Moved DynDNS Service from Apache to nginx

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:

root@host01:/etc/nginx/sites-available# ls -ls /etc/nginx/sites-available/
total 24
4 -rw-r--r-- 1 root root  650 Jul 13 18:11 dyn
4 -rw-r--r-- 1 root root  700 Jul  8 19:04 site1
4 -rw-r--r-- 1 root root  689 Jul  9 23:38 pattymitzaufen
4 -rw-r--r-- 1 root root 1055 Jul 10 13:39 smarthome
4 -rw-r--r-- 1 root root  653 Jul 10 10:57 ts3wi
4 -rw-r--r-- 1 root root  681 Jul  8 19:04 site2
root@host01:/etc/nginx/sites-available# ls -ls /etc/nginx/sites-enabled/
total 0
0 lrwxrwxrwx 1 root root 30 Jul 10 15:22 dyn -> /etc/nginx/sites-available/dyn
0 lrwxrwxrwx 1 root root 35 Jul  6 15:08 site1 -> /etc/nginx/sites-available/site1
0 lrwxrwxrwx 1 root root 41 Jul  9 23:38 pattymitzaufen -> /etc/nginx/sites-available/pattymitzaufen
0 lrwxrwxrwx 1 root root 36 Jul 10 12:21 smarthome -> /etc/nginx/sites-available/smarthome
0 lrwxrwxrwx 1 root root 32 Jul 10 10:57 ts3wi -> /etc/nginx/sites-available/ts3wi
0 lrwxrwxrwx 1 root root 33 Jul  8 19:04 site2 -> /etc/nginx/sites-available/site2
root@host01:/etc/nginx/sites-available#

Ah ok no wordpress is running on another site not on dyn.

@r0g Please run the following to list all site configurations:

ls -ls /etc/nginx/sites-available/
ls -ls /etc/nginx/sites-enabled/

If you’re using WordPress too on the same site, then the try_files should be this:

try_files $uri $uri/ /index.php?$args;