Nginx 靜態頁面POST 請求提示405 Not Allowed


從git上cp了一個開源的前端框架lay Ajax版本,用Nginx配置訪問首頁沒問題

nginx配置如下:

server
    {
        listen 80;
        server_name adminhtml.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/adminhtml;
    autoindex  on;
        include enable-php.conf;
        access_log  /home/wwwlogs/access.log;
    }

但點擊菜單(ajax實現),瀏覽器提示

Nginx: 405 Not Allowed

猜了下估計是ajax post的問題,搜索后果然

nginx是不允許post訪問靜態資源

------------------------------

解決辦法

將405狀態指向200 ok

配置Nginx如下:

server
    {
        listen 80;
        server_name adminhtml.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/adminhtml;
        location ~ .*\.(htm|html|gif|jpg|jpeg|png|ico|css|js|txt|flv|doc)$ {  
        error_page 405 =200 $uri;  
        }
    autoindex  on;
        include enable-php.conf;
        access_log  /home/wwwlogs/access.log;
    }

記得重啟Nginx

 service nginx reload

 

注意: 當允許訪問目錄時

autoindex  on;

要加編碼,否則,如果目錄或文件有中文就會顯示亂碼,so, 要加一行代碼

charset utf-8,gbk;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM