proxy模式的写法和变量

location / {
    proxy_pass http://your_backend_server;

    # Set custom headers
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;

    # Pass through all other headers
    proxy_set_header Host $host;
    proxy_set_header Connection $http_connection;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Cache-Control $http_cache_control;
    proxy_set_header Sec-CH-UA $http_sec_ch_ua;
    proxy_set_header Sec-CH-UA-Mobile $http_sec_ch_ua_mobile;
    proxy_set_header Sec-CH-UA-Platform $http_sec_ch_ua_platform;
    proxy_set_header Upgrade-Insecure-Requests $http_upgrade_insecure_requests;
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header Accept $http_accept;
    proxy_set_header Sec-Fetch-Site $http_sec_fetch_site;
    proxy_set_header Sec-Fetch-Mode $http_sec_fetch_mode;
    proxy_set_header Sec-Fetch-User $http_sec_fetch_user;
    proxy_set_header Sec-Fetch-Dest $http_sec_fetch_dest;
    proxy_set_header Accept-Encoding $http_accept_encoding;
    proxy_set_header Accept-Language $http_accept_language;
    proxy_set_header Priority $http_priority;

    # Custom headers for request time
    proxy_set_header X-Request-Time $msec;
    proxy_set_header X-Request-Time-Float $request_time;
}

fastcgi模式

        location ~ .*.php(/.*)*$ {
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_intercept_errors on;
            fastcgi_pass 127.0.0.1:9000;
        }
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param PATH_INFO $document_uri;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param HTTP_CONNECTION $http_connection;
        fastcgi_param HTTP_HOST $http_host;
        fastcgi_param HTTP_X_FORWARDED_HOST $http_x_forwarded_host;
        fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto;
        fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
        fastcgi_param HTTP_X_REAL_IP $http_x_real_ip;
        fastcgi_param HTTP_CACHE_CONTROL $http_cache_control;
        fastcgi_param HTTP_SEC_CH_UA $http_sec_ch_ua;
        fastcgi_param HTTP_SEC_CH_UA_MOBILE $http_sec_ch_ua_mobile;
        fastcgi_param HTTP_SEC_CH_UA_PLATFORM $http_sec_ch_ua_platform;
        fastcgi_param HTTP_UPGRADE_INSECURE_REQUESTS $http_upgrade_insecure_requests;
        fastcgi_param HTTP_USER_AGENT $http_user_agent;
        fastcgi_param HTTP_ACCEPT $http_accept;
        fastcgi_param HTTP_SEC_FETCH_SITE $http_sec_fetch_site;
        fastcgi_param HTTP_SEC_FETCH_MODE $http_sec_fetch_mode;
        fastcgi_param HTTP_SEC_FETCH_USER $http_sec_fetch_user;
        fastcgi_param HTTP_SEC_FETCH_DEST $http_sec_fetch_dest;
        fastcgi_param HTTP_ACCEPT_ENCODING $http_accept_encoding;
        fastcgi_param HTTP_ACCEPT_LANGUAGE $http_accept_language;
        fastcgi_param HTTP_PRIORITY $http_priority;
        fastcgi_param REQUEST_TIME $msec;
        fastcgi_param REQUEST_TIME_FLOAT $request_time;
    }
Last modification:May 22, 2024
如果觉得我的文章对你有用,请随意赞赏