Created
January 9, 2014 20:02
-
-
Save unRob/8340914 to your computer and use it in GitHub Desktop.
Routeo con path_info/nginx 101: front-controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//para el request /mira/un/salmón?color=verde | |
$segmentos = split("/", $_SERVER['PATH_INFO']); | |
//['mira', 'un', 'salmón'] | |
// o algo por el estilo... | |
$args = array_slice($segmentos, 2, count($segmentos)-2); | |
$controller = new $segmentos[0]; //new Mira | |
$controller->$segmentos[1]($args); // Mira::un('salmón'); | |
class Mira { | |
public function un($tipo) { | |
echo "Mira, un {$tipo} de color {$_GET['color']}"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
#... | |
upstream backend { | |
server unix:/private/var/tmp/php.sock; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name undominio.tld; | |
root /path/to/files; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
index index.php; | |
} | |
location ~ ^.+\.php { | |
fastcgi_split_path_info ^(.+\.php)(.*)$; | |
fastcgi_pass backend; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; | |
include fastcgi_params; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
fastcgi_param PATH_TRANSLATED $document_root/$fastcgi_path_info; | |
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 DOCUMENT_ROOT $document_root; | |
fastcgi_param SCRIPT_NAME $fastcgi_script_name; | |
fastcgi_intercept_errors off; | |
fastcgi_ignore_client_abort off; | |
fastcgi_connect_timeout 60; | |
fastcgi_send_timeout 180; | |
fastcgi_read_timeout 180; | |
fastcgi_buffer_size 128k; | |
fastcgi_buffers 4 256k; | |
fastcgi_busy_buffers_size 256k; | |
fastcgi_temp_file_write_size 256k; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment