Nginx 访问目录下载问题
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呢?

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

如何解決 Nginx 403 Forbidden 錯誤?檢查文件或目錄權限;2. 檢查 .htaccess 文件;3. 檢查 Nginx 配置文件;4. 重啟 Nginx。其他可能原因還包括防火牆規則、SELinux 設置或應用程序問題。

服務器無權訪問所請求的資源,導致 nginx 403 錯誤。解決方法包括:檢查文件權限。檢查 .htaccess 配置。檢查 nginx 配置。配置 SELinux 權限。檢查防火牆規則。排除其他原因,如瀏覽器問題、服務器故障或其他可能的錯誤。

解決 Nginx 跨域問題有兩種方法:修改跨域響應頭:添加指令以允許跨域請求,指定允許的方法和頭,以及設置緩存時間。使用 CORS 模塊:啟用模塊並配置 CORS 規則,允許跨域請求、方法、頭和設置緩存時間。

在 Linux 中啟動 Nginx 的步驟:檢查 Nginx 是否已安裝。使用 systemctl start nginx 啟動 Nginx 服務。使用 systemctl enable nginx 啟用在系統啟動時自動啟動 Nginx。使用 systemctl status nginx 驗證啟動是否成功。在 Web 瀏覽器中訪問 http://localhost 查看默認歡迎頁面。

問題的答案:304 Not Modified 錯誤表示瀏覽器已緩存客戶端請求的最新資源版本。解決方案:1. 清除瀏覽器緩存;2. 禁用瀏覽器緩存;3. 配置 Nginx 允許客戶端緩存;4. 檢查文件權限;5. 檢查文件哈希;6. 禁用 CDN 或反向代理緩存;7. 重啟 Nginx。

如何在 Windows 中配置 Nginx?安裝 Nginx 並創建虛擬主機配置。修改主配置文件並包含虛擬主機配置。啟動或重新加載 Nginx。測試配置並查看網站。選擇性啟用 SSL 並配置 SSL 證書。選擇性設置防火牆允許 80 和 443 端口流量。

確認 Nginx 是否啟動的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 檢查端口 80 是否開放;3. 查看系統日誌中 Nginx 啟動消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

查看 Nginx 運行狀態的方法有:使用 ps 命令查看進程狀態;查看 Nginx 配置文件 /etc/nginx/nginx.conf;使用 Nginx 狀態模塊啟用狀態端點;使用 Prometheus、Zabbix 或 Nagios 等監控工具。
