Nginx automatically turns my 405 status code back to 200.

Source: Internet
Author: User
Tags sendfile

First I used the symfonyhttp-foundation component.

Ajax Request Side:

$.ajax({     url:  jsui.www + 'comment/add',     data: $(this).serialize(),     type: $(this).attr('method'),     error: function(request) {            $('.comt-loading').slideUp(300);            $('.comt-error').slideDown(300).html(request.responseText);     },     success: function(data) {...}     ...

PHP Response End:

public function add(){        //header('HTTP/1.1 405 Method Not Allowed');        //echo 'Content';        //exit;  //这样写也返回200                $response = new Response(            'Content405!',            Response::HTTP_METHOD_NOT_ALLOWED,            array('content-type' => 'text/html')        );        //var_dump($response);die();        return $response; }

Nginx Configuration:

HTTP {include mime.types;    Default_type Application/octet-stream;  #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent    "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for";    #access_log Logs/access.log Main;    Sendfile on;    #tcp_nopush on;    #keepalive_timeout 0;    Keepalive_timeout 65;    #gzip on;        server {listen 8080;        server_name localhost;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            Location/{root E:\Nginx\www;            Index index.html index.htm index.php;                if (!-e $request _filename) {#一级目录下 #rewrite ^/(. *) $/index.php/$1 last;            #域名下的二级目录 rewrite ^/newblog/web/(. *) $/newblog/web/index.php/$1 last;        }} #error_page 404/404.html; # REDIRECT Server errorPages to the static page/50x.html # Error_page 502 503 504/50x.html;        Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX        Y_pass http://127.0.0.1;            #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php {            Root E:\Nginx\www;            Fastcgi_pass 127.0.0.1:9000;            Fastcgi_index index.php;        Fastcgi_split_path_info ^ (. +\.php) (. *) $;    #增加这一句 Fastcgi_param path_info $fastcgi _path_info;            #增加这一句 Fastcgi_param script_filename $document _root$fastcgi_script_name;        Include Fastcgi_params; }

This is the return

Reply content:

First I used the symfonyhttp-foundation component.

Ajax Request Side:

$.ajax({     url:  jsui.www + 'comment/add',     data: $(this).serialize(),     type: $(this).attr('method'),     error: function(request) {            $('.comt-loading').slideUp(300);            $('.comt-error').slideDown(300).html(request.responseText);     },     success: function(data) {...}     ...

PHP Response End:

public function add(){        //header('HTTP/1.1 405 Method Not Allowed');        //echo 'Content';        //exit;  //这样写也返回200                $response = new Response(            'Content405!',            Response::HTTP_METHOD_NOT_ALLOWED,            array('content-type' => 'text/html')        );        //var_dump($response);die();        return $response; }

Nginx Configuration:

HTTP {include mime.types;    Default_type Application/octet-stream;  #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent    "$http _referer" ' # ' "$http _user_agent" "$http _x_forwarded_for";    #access_log Logs/access.log Main;    Sendfile on;    #tcp_nopush on;    #keepalive_timeout 0;    Keepalive_timeout 65;    #gzip on;        server {listen 8080;        server_name localhost;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            Location/{root E:\Nginx\www;            Index index.html index.htm index.php;                if (!-e $request _filename) {#一级目录下 #rewrite ^/(. *) $/index.php/$1 last;            #域名下的二级目录 rewrite ^/newblog/web/(. *) $/newblog/web/index.php/$1 last;        }} #error_page 404/404.html; # REDIRECT Server errorPages to the static page/50x.html # Error_page 502 503 504/50x.html;        Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX        Y_pass http://127.0.0.1;            #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php {            Root E:\Nginx\www;            Fastcgi_pass 127.0.0.1:9000;            Fastcgi_index index.php;        Fastcgi_split_path_info ^ (. +\.php) (. *) $;    #增加这一句 Fastcgi_param path_info $fastcgi _path_info;            #增加这一句 Fastcgi_param script_filename $document _root$fastcgi_script_name;        Include Fastcgi_params; }

This is the return

This should be okay with nginx.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.