Nginx 访问目录下载问题

WBOY
풀어 주다: 2016-06-06 20:42:26
원래의
1110명이 탐색했습니다.

nginx虚拟主机,在本地做的测试,部分配置如下:

<code>server {
listen      80;
server_name     www.myblog.com;

error_page  404  /404.html;
error_page   500 503 504  /50x.html;

# server_name_in_redirect off;

root  /usr/share/nginx/www/myblog;

# default_type  application/octet-stream;

index index.html index.php;

location / {
    try_files $uri $uri/ /index.html;
}
location ~*\.(gif|jpg|png)$ {
    expires 30d;
}
location ~ \.php {
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  PATH_INFO $fastcgi_script_name;      
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
}
</code>
로그인 후 복사
로그인 후 복사

}

现在的问题是当我访问www.myblog.com的时候会下载index.php,而不是执行。但我访问www.myblog.com/index.php的时候却是ok的。

请问这个问题怎么解决?

多谢各位!

回复内容:

nginx虚拟主机,在本地做的测试,部分配置如下:

<code>server {
listen      80;
server_name     www.myblog.com;

error_page  404  /404.html;
error_page   500 503 504  /50x.html;

# server_name_in_redirect off;

root  /usr/share/nginx/www/myblog;

# default_type  application/octet-stream;

index index.html index.php;

location / {
    try_files $uri $uri/ /index.html;
}
location ~*\.(gif|jpg|png)$ {
    expires 30d;
}
location ~ \.php {
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  PATH_INFO $fastcgi_script_name;      
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
}
</code>
로그인 후 복사
로그인 후 복사

}

现在的问题是当我访问www.myblog.com的时候会下载index.php,而不是执行。但我访问www.myblog.com/index.php的时候却是ok的。

请问这个问题怎么解决?

多谢各位!

问题解决了,原来是浏览器缓存的问题,清除一下缓存就可以了!!!泪奔啊。。。

可以参考这里:http://serverfault.com/questions/315224/why-are-my-php-files-downloading-instead-of-processing-with-nginx?rq=1

多谢各位的回答了!

在try_files最后添加index.php试试看

try_files $uri $uri/ /index.html; 这里是不是少了 index.php呢?

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!