2017-05-03 4 views
0

Ich habe ein paar APIs, die Oauth (nicht Oauth2) verwenden, beendet. Wir verschieben alle unsere Seiten von Apache auf Nginx (mit fastcgi) und ich stoße auf ein Problem mit Anfrage-Header nicht gesendet werden. Ich habe zahlreiche Posts und die Nginx-Dokumente gelesen und bin immer noch nicht in der Lage, die Header-Parameter zu durchlaufen.Übergeben Anforderungsheader mit fastcgi in Nginx

ich Postman bin mit API-Anfragen zu machen und das Setzen dieser Header:

Postman headers

Ich habe schließlich verwalten den Schlüssel des Kopf aufstehen zu zeigen, wenn ich var_dump($_SERVER); aber ich nicht den tatsächlichen Wert bekommen passieren.

Hier ist mein Haupt nginx.confhttp Block:

http { 
    include mime.types; 
    default_type application/octet-stream; 

    sendfile on; 
    keepalive_timeout 6000; 
    client_max_body_size 128M; 

    gzip on; 
    gzip_comp_level 5; 
    gzip_min_length 256; 
    gzip_proxied any; 
    gzip_vary on; 

    gzip_types 
    application/atom+xml 
    application/javascript 
    application/json 
    application/rss+xml 
    application/vnd.ms-fontobject 
    application/x-font-ttf 
    application/x-web-app-manifest+json 
    application/xhtml+xml 
    application/xml 
    font/opentype 
    image/svg+xml 
    image/x-icon 
    text/css 
    text/plain 
    text/x-component; 

    include /Users/webdev2/.valet/Nginx/*; 
    include servers/*; 
    include valet/valet.conf; 
} 

Und hier ist mein valet.conf:

server { 
    listen 80 default_server; 
    root /; 
    charset utf-8; 

    location /41c270e4-5535-4daa-b23e-c269744c2f45/ { 
     internal; 
     alias /; 
     try_files $uri $uri/; 
    } 

    location/{ 
     rewrite^/Users/webdev2/.composer/vendor/laravel/valet/server.php last; 
    } 

    location = /favicon.ico { access_log off; log_not_found off; } 
    location = /robots.txt { access_log off; log_not_found off; } 

    access_log off; 
    error_log /Users/webdev2/.valet/Log/nginx-error.log; 

    error_page 404 /Users/webdev2/.composer/vendor/laravel/valet/server.php; 

    location ~ \.php$ { 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/Users/webdev2/.valet/valet.sock; 
    fastcgi_pass_request_headers on; 
    fastcgi_pass_header Authorization; 
    fastcgi_pass_header http_oauth_token; 
    fastcgi_pass_header oauth_token_secret; 
     fastcgi_index /Users/webdev2/.composer/vendor/laravel/valet/server.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME /Users/webdev2/.composer/vendor/laravel/valet/server.php; 
     fastcgi_read_timeout 300; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 
} 

Und schließlich, hier ist meine fastcgi_params Datei:

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_FILENAME $request_filename; 
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 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; 
fastcgi_param HTTPS $https if_not_empty; 
fastcgi_param REDIRECT_STATUS 200; 
fastcgi_param HTTP_PROXY ""; 
fastcgi_param HTTP_AUTHORIZATION $http_authorization; 
fastcgi_param OAUTH_TOKEN $http_oauth_token; 
fastcgi_param OAUTH_TOKEN_SECRET $http_oauth_token_secret; 

Hier ein Bild der Antwort des var_dump($_SERVER). HINWEIS: Diese var_dump ist bevor alles andere in der App aufgerufen wird.

enter image description here

Antwort

0

Nun, nach 2 Tagen Graben um und versuchen, um dies herauszufinden, ich habe es endlich funktioniert. Das fehlende Stück war diese Zeile hinzufügen:

underscores_in_headers on;

In meinem Haupt http Block im nginx.conf. Also, hier ist, was der letzte http Block von meinem nginx.conf aussieht:

http { 
    include mime.types; 
    default_type application/octet-stream; 

    sendfile on; 
    keepalive_timeout 6000; 
    client_max_body_size 128M; 

    gzip on; 
    gzip_comp_level 5; 
    gzip_min_length 256; 
    gzip_proxied any; 
    gzip_vary on; 

    gzip_types 
    application/atom+xml 
    application/javascript 
    application/json 
    application/rss+xml 
    application/vnd.ms-fontobject 
    application/x-font-ttf 
    application/x-web-app-manifest+json 
    application/xhtml+xml 
    application/xml 
    font/opentype 
    image/svg+xml 
    image/x-icon 
    text/css 
    text/plain 
    text/x-component; 

    underscores_in_headers on; # This beauty right here :D 

    include /Users/webdev2/.valet/Nginx/*; 
    include servers/*; 
    include valet/valet.conf; 
} 
Verwandte Themen