靜態頁接收post請求

默認情況下,nginx、apache、IIs等web服務無法響應靜態頁面的post請求,後端用來處理post請求,生產環境中不會有此問題(一般都不允許配置靜態頁面的post請求)
爲什麼默認不支持靜態頁面post請求呢?
首先了解一下post請求方法,post請求一般用於提交表單或上傳文件,post請求會導致新資源的建立或舊資源的更改。就安全方面來說(排除url地址的透明性),它對比get請求會有更改資源的情況,有些靜態資源是不允許更改的,所以默認情況下web服務器上的靜態資源都不允許發起post請求。
有時候開發會寫個json頁面,它需要給領導展示,但是默認不允許發起post請求,就需要配置,這裏以nginx爲例,

    upstream static_backend {
        server localhost:80;
       }
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
       error_page 405 =200 @405;
       location @405 {
        root /html;
        proxy_method GET;
        proxy_pass http://static_backend;
       } 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章