簡體   English   中英

Nginx顯示除首頁以外的所有頁面均未找到404

[英]Nginx showing 404 Not Found for every page but homepage

我正在嘗試在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;
}

}

似乎您有一個.htaccess,它將每個請求都路由到index.php。由於nginx無法理解.htaccess文件,因此您必須使用nginx重寫此文件。請參閱https://winginx.com/zh_CN/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;
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM