2016-08-09 10 views
0

Ich möchte den gesamten Verkehr an eine .php Datei übergeben, versuchte dies aber nicht funktioniert. Ich verwende nginx 1.10.0Übergeben Sie alles an einen Ort Nginx

Hier Ausgabe von nginx -V:

nginx Version: nginx/1.10.0 (Ubuntu) gebaut mit OpenSSL 1.0.2g-fips 1. März 2016 TLS SNI Unterstützung aktiviert konfiguriere Argumente: --with-cc-opt = '- g -O2 -fPIE -fstack-protector-strong -Wormat -Werror = Format-Sicherheit -Wedate-Zeit -D_FORTIFY_SOURCE = 2' --with-ld-opt = ' -Wl, -Bsymbolische-Funktionen -fPIE -pie -Wl, -z, relro -Wl, -z, jetzt '--prefix =/usr/share/nginx --conf-pfad =/etc/nginx/nginx.conf --http-Protokollpfad =/var/Protokoll/nginx/access.log --error-Protokollpfad =/var/Protokoll/nginx/error.log --lock-Pfad =/var/lock/nginx.lock --pid-Pfad =/run/nginx.pid - -http-client-body-temp-pfad =/var/lib/nginx/body --http-schnellecgi-temp-pfad =/var/lib/nginx/schnelle cgi --http-proxy-temp-pfad =/var/lib/nginx/proxy --http-scgi-temp-pfad =/var/lib/nginx/scgi --http-uwsgi-temp-pfad =/var/lib/nginx/uwsgi - mit-debug --with- pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_modul --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_geoip_module - with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module - mit-mail --with-mail_ssl_module --mit-stream --mit-stream_ssl_modul --mit-threads --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/headers-more- nginx-modul --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx-auth-pam - add-module =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx-cache-purge --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx -dav-ext-modul --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx-entwicklungs-kit --add-modul =/build/nginx-wAi2qr/nginx-1.10 .0/debian/modules/nginx-echo --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/ngx-fancyindex --add-modul =/build/nginx-wAi2qr/nginx -1.10.0/debian/modules/nginx-http-push --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx-lua --add-modul =/build/nginx -wAi2qr/nginx-1.10.0/debian/Module/nginx-upload-progress --add-modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/nginx-upstream-fair --add- Modul =/build/nginx-wAi2qr/nginx-1.10.0/debian/modules/ngx_http_substitutions_filter_module

server { 
    listen 80 default_server; 

    server_name _; 

    location/{ 

     include /etc/nginx/snippets/fastcgi-php.conf; 

     fastcgi_param SCRIPT_FILENAME /location/to/php/cache.php;  
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 

    } 


    # Set maximum expire to all static files 

    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 
     access_log off; 
     log_not_found off; 
     expires max; 
    } 

} # server 
Folgende Konfiguration
+0

Was genau erwarten Sie zu erreichen? Möchten Sie den Ausführungsfluss für jede Anfrage (auch für statische Dateien) in die cache.php übergeben? Was ist in deiner cache.php? Was ist in Nginx-Logs? Welche Art von Fehler hast du jetzt? – oakymax

Antwort

0

Versuchen:

server { 
    listen 80 default_server; 

    server_name _; 

    root /location/to/php; 
    index cache.php; 

    location/{ 
     rewrite ^/(.*)$ /cache.php?requestedPath=$1 break; 
     include /etc/nginx/snippets/fastcgi-php.conf; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 


    # Set maximum expire to all static files 

    location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|t gz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { 
     access_log off; 
     log_not_found off; 
     expires max; 
    } 

} # server 

Dann können Sie requestedPath von GET params in Ihrem cache.php verwenden.

Diese Konfiguration leitet jedoch den Ausführungsfluss für statische Dateien nicht an PHP um. Wenn Sie Bilder und andere statische Dateien in Ihrem cache.php verarbeiten möchten, sollten Sie add to second location die gleichen Zeilen wie im ersten Block hinzufügen.

Verwandte Themen