I am attempting to setup a nginx site, and had to convert the .htaccess as it was designed for apache but every time i attempt to access a page it is downloading the php file instead of loading the page.
server {
server_name theminecraftservers.net;
root /var/www/tms;
index list.php index index.htm;
error_page 500 http://localhost/not-found;
error_page 404 http://localhost/not-found;
error_page 403 http://localhost/not-found;
location ~ index.html$ {
rewrite ^(.*)$ / redirect;
}
location ~ index.php$ {
rewrite ^(.*)$ / redirect;
}
autoindex off;
location = /captcha.png {
rewrite ^(.*)$ /engine/captcha/captcha.php break;
}
location / {
try_files $uri $uri/ /list.php?q=$uri&$args;
rewrite "^/banner-([0-9]{0,5})-([0-9]{1,5}).gif$" /engine/banner.php?id=$1&code=$2 break;
rewrite "^/icon-([0-9]{0,5})-([0-9]{1,5}).png$" /engine/icon.php?id=$1&code=$2 break;
rewrite "^/votebanner-([0-9]{1,5})-([A-Za-z0-9-]{3,6}).png$" /engine/vote-banner.php?id=$1&color=$2 break;
rewrite ^/$ /list.php?lang=&page=&category=&pg=1 break;
rewrite "^/pg.([0-9]{1,9})$" /list.php?lang=&page=&category=&pg=$1 break;
rewrite "^/versions/([0-9a-z.-]+)/pg.([0-9]{1,9})$" /list.php?lang=&page=&category=versions&query=$1&pg=$2 break;
rewrite "^/types/([0-9a-z.-]+)/pg.([0-9]{1,9})$" /list.php?lang=&page=&category=types&query=$1&pg=$2 break;
rewrite "^/cp/server/([a-z-]+).([0-9]{1,6})$" /list.php?lang=&page=cp&sub=server&action=$1&id=$2 break;
rewrite "^/cp/admin/([a-z-]+)/([0-9]{1,6}).([a-z-]+)$" /list.php?lang=&page=cp&sub=admin&admin_sub=$1&id=$2&action=$3 break;
rewrite "^/cp/admin/servers/pg.([0-9]{1,9})$" /list.php?lang=&page=cp&sub=admin&admin_sub=servers&pg=$1 break;
rewrite ^/([0-9a-z-]+)$ /list.php?lang=&page=$1 break;
rewrite "^/recover-password/id.([A-Za-z0-9-]{1,50})$" /list.php?lang=&page=recover-password&id=$1 break;
rewrite "^/servers-search/q=([^\.]{3,50})&cat=([0-9]{1})$" /list.php?&page=servers-search&query=$1&cat=$2 break;
rewrite "^/([a-z-]{2,5})/$" /list.php?lang=$1&page=&category=&pg=1 break;
rewrite "^/([a-z-]{2,5})/pg.([0-9]{1,9})$" /list.php?lang=$1&page=&category=&pg=$2 break;
rewrite "^/([a-z-]{2,5})/versions/([0-9a-z.-]+)$" /list.php?lang=$1&page=&category=versions&query=$2&pg=1 break;
rewrite "^/([a-z-]{2,5})/versions/([0-9a-z.-]+)/pg.([0-9]{1,9})$" /list.php?lang=$1&page=&category=versions&query=$2&pg=$2 break;
rewrite "^/([a-z-]{2,5})/types/([0-9a-z.-]+)$" /list.php?lang=$1&page=&category=types&query=21&pg=1 break;
rewrite "^/([a-z-]{2,5})/types/([0-9a-z.-]+)/pg.([0-9]{1,9})$" /list.php?lang=$1&page=&category=types&query=$2&pg=$2 break;
rewrite "^/([a-z-]{2,5})/cp/([0-9a-z-]+)$" /list.php?lang=$1&page=cp&sub=$2 break;
rewrite "^/([a-z-]{2,5})/sponsored$" /list.php?lang=$1&page=cp&sub=sponsored&message= break;
rewrite "^/([a-z-]{2,5})/sponsored/status=thankyou$" /list.php?lang=$1&page=cp&sub=sponsored&message=1 break;
rewrite "^/([a-z-]{2,5})/cp/server/([a-z-]+).([0-9]{1,6})$" /list.php?lang=$1&page=cp&sub=server&action=$2&id=$3 break;
rewrite "^/([a-z-]{2,5})/cp/admin/([a-z-]+)$" /list.php?lang=$1&page=cp&sub=admin&admin_sub=$2 break;
rewrite "^/([a-z-]{2,5})/cp/admin/([a-z-]+)/([a-z-]+)$" /list.php?lang=$1&page=cp&sub=admin&admin_sub=$2&action=$3 break;
rewrite "^/([a-z-]{2,5})/cp/admin/([a-z-]+)/([0-9]{1,6}).([a-z-]+)$" /list.php?lang=$1&page=cp&sub=admin&admin_sub=$2&id=$3&action=$4 break;
rewrite "^/([a-z-]{2,5})/cp/admin/servers/pg.([0-9]{1,9})$" /list.php?lang=$1&page=cp&sub=admin&admin_sub=servers&pg=$2 break;
rewrite "^/([a-z-]{2,5})/([0-9a-z-]+)$" /list.php?lang=$1&page=$2 break;
rewrite "^/server-([^\.]+).([0-9]{1,4})$" /list.php?lang=&page=server&title=$1&id=$2&sub= break;
rewrite "^/server-([^\.]+).([0-9]{1,4})/([a-z]+)$" /list.php?lang=&page=server&title=$1&id=$2&sub=$3 break;
rewrite "^/([a-z-]{2,5})/server-([^\.]+).([0-9]{1,4})$" /list.php?lang=$1&page=server&title=$2&id=$3&sub= break;
rewrite "^/([a-z-]{2,5})/server-([^\.]+).([0-9]{1,4})/([a-z]+)$" /list.php?lang=$1&page=server&title=$2&id=$3&sub=$4 break;
rewrite "^/([a-z-]{2,5})/recover-password/id.([A-Za-z0-9-]{1,50})$" /list.php?lang=$1&page=recover-password&id=$2 break;
rewrite "^/([a-z-]{2,5})$" /$1/ redirect;
rewrite ^/(.*)/$ /$1 redirect;
}
location = /robots.txt {
rewrite ^(.*)$ /robots.txt break;
}
location = /sitemap.xml {
rewrite ^(.*)$ /list.php?page=sitemap break;
}
location /versions {
rewrite ^/versions/([0-9a-z.-]+)$ /list.php?lang=&page=&category=versions&query=$1&pg=1 break;
}
location /types {
rewrite ^/types/([0-9a-z.-]+)$ /list.php?lang=&page=&category=types&query=$1&pg=1 break;
}
location /cp {
rewrite ^/cp/([0-9a-z-]+)$ /list.php?lang=&page=cp&sub=$1 break;
rewrite ^/cp/admin/([a-z-]+)$ /list.php?lang=&page=cp&sub=admin&admin_sub=$1 break;
rewrite ^/cp/admin/([a-z-]+)/([a-z-]+)$ /list.php?lang=&page=cp&sub=admin&admin_sub=$1&action=$2 break;
}
location = /sponsored {
rewrite ^(.*)$ /list.php?lang=&page=cp&sub=sponsored&message= break;
}
location /sponsored {
rewrite ^/sponsored/status=thankyou$ /list.php?lang=&page=cp&sub=sponsored&message=1 break;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/projectluna.app-error.log error;
# allow larger file uploads and longer script runtimes
client_max_body_size 100m;
client_body_timeout 120s;
sendfile off;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index list.php;
include fastcgi_params;
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/theminecraftservers.net/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/theminecraftservers.net/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 = theminecraftservers.net) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name theminecraftservers.net;
return 404; # managed by Certbot
}
Any Ideas?
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!
Hello,
Usually when the webpage is downloading it’s related to the configuration being able to read something. Looking at the Nginx configuration file everything looks fine. I can’t find any typos at first glance. What I’ll recommend would be to comment each line one by one to troubleshoot which one is causing these issues.
I’ll recommend starting with the PHP lines usually it’s coming from them.
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.