Using nginx reverse proxy dynamic request, login can not be recognized, and it is found that the session of each request will change.

server {

    listen       80;
    server_name  localhost;

    -sharpcharset koi8-r;

    -sharpaccess_log  logs/host.access.log  main;

    -sharp location / {
    -sharp     root   html;
    -sharp     index  index.html index.htm;
    -sharp }

    

    location ~*\.(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf|json|ico|htc|ttf)$ {
                root C:/workspace/fenzhi/cloudkit/cloudkit-workbench/src/main/webapp;
                index  index.html index.htm;
    }

    location  ~*/[^\.] {
                 proxy_pass http://webtest.guanmaoyun.net;
                -sharp proxy_set_header Host $host;  
                -sharp proxy_set_header X-Real-IP $remote_addr;  
                -sharp proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                
                -sharp proxy_cookie_domain localhost http://webtest.guanmaoyun.net;
                proxy_cookie_path / /workbench/;
                -sharp proxy_set_header Cookie $http_cookie;
                 -sharpinclude proxy.conf;
                         -sharpproxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
             }

    

    -sharperror_page  404              /404.html;

    -sharp redirect server error pages to the static page /50x.html
    -sharp
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    -sharp proxy the PHP scripts to Apache listening on 127.0.0.1:80
    -sharp
    -sharplocation ~ \.php$ {
    -sharp    proxy_pass   http://127.0.0.1;
    -sharp}

    -sharp pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    -sharp
    -sharplocation ~ \.php$ {
    -sharp    root           html;
    -sharp    fastcgi_pass   127.0.0.1:9000;
    -sharp    fastcgi_index  index.php;
    -sharp    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    -sharp    include        fastcgi_params;
    -sharp}

    -sharp deny access to .htaccess files, if Apache"s document root
    -sharp concurs with nginx"s one
    -sharp
    -sharplocation ~ /\.ht {
    -sharp    deny  all;
    -sharp}
}

the main static requests will be transferred to this directory, and the dynamic requests will be proxied back to http://webtest.guanmaoyun.net.

Mar.09,2022

session needs the support of cookie !

the key points of the general principle are:

  • http is stateless, that is, without extra parameter support, the backend of each request will not know who sent it
  • cookie is automatically sent to the background when each request is made, and the backend also sends cookie back when it responds, and both the frontend and backend can modify cookie .
  • cookie is time-limited and is restricted by homologous policy
  • The implementation of session is based on cookie , which has a key-like value that uniquely identifies session .
  • session needs to be cached, such as redis , etc.
The description of the problem in

supporting analysis is not enough, so it is difficult to find out the specific reason. I hope I can help you solve the problem through session principle

.
Menu