2016-06-13 92 views
1

我想在ubuntu上的nginx服务器上运行一个php应用程序。我确实把我所有的文件放在var/www/mydomain.com.html中,它完美地呈现了我的index.php。但是,即使这些文件存在于同一目录中,也会显示404 Not Found for every page。Nginx显示404没有找到每个页面,但主页

这是我的服务器块配置。

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

这似乎是你有一个.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; 
} 
} 
+0

我应该把这个rewrited htaccess放在服务器块,nginx.conf还是其他地方? – Mohan

+0

这应该工作,但要更有组织,你可以创建一个额外的文件 – Sebastian

+0

感谢您的建议:) – Mohan