Reputation: 121
I implement web server on nginx with Php framework without any index.html, web page works fine, but some script doesnt working, it says "500 internal server error"
Here's the server log
2016/11/16 11:08:38 [error] 2551#0: *738 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /kelontong/getKelontong HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:09:20 [error] 2551#0: *746 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /kelontong/getKelontong HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:14:47 [error] 5500#0: *4 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /department/ HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:14:48 [error] 5500#0: *6 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /department/getdepartment HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:18:56 [error] 5518#0: *4 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /department/getdepartment HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:18:56 [error] 5520#0: *8 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /department/getdepartment HTTP/1.1", host: "192.168.70.86"
2016/11/16 11:21:35 [error] 5534#0: *3 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 27.131.251.6, server: www.foreverstore.id, request: "GET /department/getdepartment HTTP/1.1", host: "192.168.70.86"
And here's my nginx host config file
server {
listen 443 ssl http2;
root /bwi/foreverstore.id;
index index.html index.htm index.php;
server_name www.foreverstore.id ;
ssl_certificate /etc/nginx/ssl/foreverstore.crt;
ssl_certificate_key /etc/nginx/ssl/foreverstore.key;
location / {
try_files $uri $uri/ /index.html;
# try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.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;
fastcgi_intercept_errors on;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
}
}
if you guys know how to solve this problem, i will be thankfull to you cheers.
Upvotes: 11
Views: 32207
Reputation: 96
The problem comes from this line :
try_files $uri $uri/ /index.html;
The error occurs when neither $uri, $uri/, nor /index.html exist on your server.
/index.html is the fallback, so if $uri and $uri/ don't exist, nginx will try again with index.html. But if index.html doesn't exist, nginx will retry indefinitely.
One solution is to transform the line into :
try_files $uri $uri/ /index.html =404;
So that nginx won't indefinitely loop, and just send a 404 error if neither $uri, $uri/, nor /index.html exist on your server.
Upvotes: 0
Reputation: 931
Since you ain't using any html files as you stated, change your root location block:
location / {
try_files $uri $uri/ =404;
}
You have to include a try files as well in your php block so when it FAILS it goes there instead of seeking a redirect:
location ~ \.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;
fastcgi_intercept_errors on;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
try_files $uri $uri/ =404;
}
Since you declared: error_page 404 /404.html;
you can also add the 404 location:
location = /404.html {
root /usr/share/nginx/html/;
internal;
}
This should stop those ugly redirect loops.
Upvotes: -1
Reputation: 5419
I think the try_files line should look like:
try_files $uri $uri/ index.html;
Upvotes: 6