The status code returned by the nginx agent is inconsistent with that returned by the direct access application.

problem description

directly use the browser to access our backend interface. In the case of not logging in, the status code returned by the API is 401, and the return path is / user/requireLogin,. But now we configure nginx at the front end to solve the cross-domain problem, and the calling interface returns 200. What should I do if I want nginx to return 401 as well?

the platform version of the problem and what methods you have tried

our nginx is the latest 1.14, and the platform is nginx

related codes

/ / Please paste the code text below (do not replace the code with pictures)


worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       10.67.1.102:80;
        server_name  10.67.1.102;
        rewrite ^(.*)$  https://$host$1 permanent;          
    }
    server {
        listen       10.67.1.102:443;
        server_name  10.67.1.102;
        client_max_body_size   20m;
        proxy_redirect      off;
        proxy_set_header    Host                    $host;
        proxy_set_header    X-Real-IP               $remote_addr;
        proxy_set_header    X-Forwarded-Host        $host:$server_port;
        proxy_set_header    X-Forwarded-Server      $host;
        proxy_set_header    X-Forwarded-For         $proxy_add_x_forwarded_for;
        proxy_set_header     X-Forwarded-Proto $scheme;
        proxy_pass_header   Set-Cookie;
        proxy_pass_header   P3P;
        proxy_buffering     off;  
        proxy_intercept_errors off; 
        ssl          on;
        ssl_certificate        ./server.crt;
        ssl_certificate_key    ./server.key;        

        -sharpaccess_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }

        location /WebApi/jjjj/static/ {
            alias  E:/svn/06_code/dist/ZJYD/;
            index  index.html index.htm;

        }
        -sharp
        location /jjjj/api/v1 {
            add_header "Access-Control-Allow-Origin" "$http_origin";
            add_header "Access-Control-Allow-Credentials" "true";
            add_header "Access-Control-Allow-Methods" "GET, PUT, POST, DELETE, OPTIONS";
            add_header "Access-Control-Allow-Headers" "Content-Type,*";    
            proxy_pass  https://10.67.1.101/jjjj/api/v1/;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location = /user/requireLogin {
            alias html/401.html;
        }



    }





}

what result do you expect? What is the error message actually seen?

now I want nginx to return the same status code as directly accessing the background interface. What should I do? I don"t have a clue.

Apr.03,2021

try this

location = /user/requireLogin {
    error_page 401 html/401.html;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaac9d-69775.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaac9d-69775.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?