我正在尝试在ubuntu上的nginx服务器上运行一个php应用程序。我确实将所有文件都放在var / www / mydomain.com.html中。它完全呈现了我的index.php。但是对于每个其他页面显示404 Not Found,即使这些文件存在于同一目录中。
这是我的服务器块配置。
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80; ## listen for ipv6
root /var/www/app.limoposter.com/html;
index index.php index.html index.htm;
server_name app.limoposter.com www.app.limoposter.com;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
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;
}
}
答案 0 :(得分:2)
好像你有一个.htaccess,它将每个请求都路由到你的index.php 由于nginx不了解.htaccess文件,你必须使用nginx重写它 见https://winginx.com/en/htaccess
编辑: 我下载了你的.htaccess并使用了上面提到的转换器: 这是输出:
autoindex off;
location / {
if ($script_filename !~ "-d"){
rewrite ^/login/(.*)/$ /login.php?type=$1 break;
}
if ($script_filename !~ "-d"){
rewrite ^/dashboard/(.*)/$ /dashboard.php?show=$1 break;
}
if ($script_filename !~ "-d"){
rewrite ^/admin/(.*)/$ /admin.php?module=$1 break;
}
if ($script_filename !~ "-d"){
rewrite ^/(.*)/$ /$1.php break;
}
if ($request_uri ~ "storage/(\d+)_(.*)$"){
rewrite ^/storage/(\d+)_(\d+)/([a-zA-Z0-9_]+).([a-zA-Z0-9_\.]+)$ /download.php?folder=$1_$2&file=$3.$4 break;
}
}