Nginx automatically converts the 405 status code returned to 200

Source: Internet
Author: User
Tags sendfile
First, I used the symfonyhttp-foundation component. Ajax request end: {code...} php response end: {code...} nginx configuration: {code...} This is returned

First, I used the symfonyhttp-foundation component.

Ajax request end:

$.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; // in this case, 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 $ response "$ 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; # chars Et 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 error pages to the static page/50x.html # error_page 500 502 503 x.html; location =/50x.html {root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1: 80 # location ~ \. Php $ {# proxy_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 )(. *) $; # add the fastcgi_param PATH_INFO $ fastcgi_path_info; # add the fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params ;}

This is returned

Reply content:

First, I used the symfonyhttp-foundation component.

Ajax request end:

$.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; // in this case, 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 $ response "$ 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; # chars Et 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 error pages to the static page/50x.html # error_page 500 502 503 x.html; location =/50x.html {root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1: 80 # location ~ \. Php $ {# proxy_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 )(. *) $; # add the fastcgi_param PATH_INFO $ fastcgi_path_info; # add the fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params ;}

This is returned

This should be irrelevant to nginx.

Related Article

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.