duanping3587 2016-06-13 19:10
浏览 254

Nginx显示除了主页之外的每个页面都找不到404 Not Found

I am trying to run a php app on nginx server on ubuntu. I did put all my files in var/www/mydomain.com.html It's rendering my index.php perfectly. But showing 404 Not Found for every other page even though those files are exists in the same directory.

Here is my server block configuration.

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;
}

}

  • 写回答

1条回答 默认 最新

  • duanhao4156 2016-06-13 19:40
    关注

    It seems like you have an .htaccess which routes every request to your index.php Since nginx doesn't understand .htaccess files, you'll have to rewrite this using nginx See https://winginx.com/en/htaccess

    Edit: I downloaded your .htaccess and used the converter mentioned above: This is the output:

    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;
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据