Nginx·ºÓòÃû½âÎö¼°RewriteÖض¨ÏòÆÕͨҳÃæ¼°´ø²ÎÊýµÄÒ³Ãæ(2)
3¡¢server_name_in_redirect off;½âÊÍ˵Ã÷
ÔÚijЩÇé¿öÏ£¨¾ßÌå¿É²Î¿¼ wiki.nginx.org£©£¬Nginx ÄÚ²¿Öض¨Ïò¹æÔò»á±»Æô¶¯£¬ÀýÈ磬µ± URL Ö¸ÏòÒ»¸öĿ¼²¢ÇÒÔÚ×îºóûÓаüº¬¡°/¡±Ê±£¬Nginx ÄÚ²¿»á×Ô¶¯µÄ×öÒ»¸ö 301 Öض¨Ïò£¬Õâʱ»áÓÐÁ½ÖÖÇé¿ö£º
1¡¢server_name_in_redirect on£¨Ä¬ÈÏ£©£¬URL Öض¨ÏòΪ£º server_name ÖеĵÚÒ»¸öÓòÃû + Ŀ¼Ãû + /£»
2¡¢server_name_in_redirect off£¬URL Öض¨ÏòΪ£º Ô URL ÖеÄÓòÃû + Ŀ¼Ãû + /¡£
µ±ÄãÓжà¸öÓòÃûÒªÖ¸Ïòͬһ¸öÐéÄâÖ÷»ú£¬²¢ÇÒÄã×Ô¼ºÐ´ 301 Öض¨Ïò¹æÔò°ÑËüÃǺϲ¢µ½Ä³Ò»¸öÓòÃûʱ£¬Çé¿ö¾Í¸ü¸´ÔÓÁË£º
Ê×ÏÈ£¬nginx ¼ì²é URL£¬Èç¹û·ûºÏÌõ¼þ£¬¾ÍÓøùæÔò£¨ÄãдµÄ£©×öµÚÒ»±éÖض¨Ïò£¬½Ó×Å£¬¼ì²éÐÂÉú³ÉµÄ URL£¬Èç¹û·ûºÏÄÚ²¿×Ô¶¯Öض¨ÏòÖ®Ìõ¼þ£¬¾ÍÓÃÇ°ÃæÌáµ½µÄ¹æÔòÔÙ×öÒ»´ÎÖض¨Ïò¡£
ÖÁÓÚ PHP µÄ $_SERVER["SERVER_NAME"]£¬ÔÚ nginx ÖÐĬÈÏÊÇÓÉ nginx µÄ±äÁ¿ $server_name Ìṩ£¬ÕâʱËüºÍÖض¨ÏòûÓйØϵ£¬Ê¼ÖÕÊÇ server_name ÉèÖÃÖеĵÚÒ»¸öÓòÃû£¬µ«ÕâÊÇ¿ÉÒÔ±»¸Ä±äµÄ£¬ÔÚÄãµÄ nginx ÅäÖÃÖÐÕÒµ½ fastcgi_param ²¿·Ö£¬ÐÞ¸Ä
fastcgi_param SERVER_NAME $server_name;
Ϊ
fastcgi_param SERVER_NAME $host;
µ«ÏÖÔÚ¾ÍҪעÒâÁË£¬´ËʱµÄ $_SERVER["SERVER_NAME"] »áÊÜÄãдµÄºÍ nginx ×Ô¼ºµÄÖض¨Ïò¹æÔòËùÓ°Ïì¶ø±ä»¯¡£
ÏÖÔÚ¾ÍÇå³þÁË£¬Èç¹û MediaWiki ÊÇͨ¹ý $_SERVER["SERVER_NAME"] À´×Ô¼º´¦Àí URL µÄ»°£¬ÄÇôÔÚ nginx + php µÄĬÈÏ»·¾³Ï£¬Ëü»ñµÃµÄ½«Ê¼ÖÕÊÇ server_name ÉèÖÃÖеĵÚÒ»¸öÓòÃû£¬ËùÒÔÔì³ÉÁË¡°²»¹Üͨ¹ýʲôÓòÃû·ÃÎÊ MediaWiki Ê×Ò³£¬¶¼»á±»Ìøתµ½ÆäÖеÄÒ»¸öÓòÃûÉÏ¡£¡±£¬Õâ²»ÊÇ nginx µÄÖض¨ÏòÔì³ÉµÄ£¬ËäȻĬÈÏ server_name_in_redirect ÊÇ on£¬µ«Õâ¸öÖ¸ÁîµÄÓ°Ï췶Χ½ö½öÖ»ÊÇ nginx ×Ô¼ºÄÚ²¿µÄÖض¨Ïò¹æÔò£¬ËùÒÔ£¬µ±ÄãÔÚ nginx + php µÄ»·¾³ÖÐʹÓöàÓòÃûÐéÄâÖ÷»ú£¬²¢ÇÒÄãµÄ php ¿â¡¢¿ò¼Ü¡¢´úÂë´óÁ¿Ê¹Óà $_SERVER["SERVER_NAME"] ʱ£¬ÄãÒ²ÐíÓ¦¸Ã£º
1¡¢ÉèÖà fastcgi_param SERVER_NAME $host;
2¡¢ÉèÖà server_name_in_redirect off; Èà nginx ÔÚ´¦Àí×Ô¼ºÄÚ²¿Öض¨Ïòʱ²»Ä¬ÈÏʹÓà server_name ÉèÖÃÖеĵÚÒ»¸öÓòÃû£»
3¡¢²»ÒªÊ¹Óà nginx µÄ rewrite ¹æÔòÀ´Öض¨Ïò¡¢ºÏ²¢¶à¸öÓòÃû¡£
µ±È»£¬ºóÁ©ÌõÊÇÍêÈ«¿ÉÑ¡µÄ£¬Ç°ÌáÊÇÄãÇå³þÄãÔÚ×öʲô²¢ÇÒСÐÄ´¦ÀíÕâʱµÄ $_SERVER["SERVER_NAME"]£¬Ò²Ðí¸üºÃµÄ×ö·¨ÊDZ£³Ö fastcgi_param SERVER_NAME $server_name; £¬È»ºóºÏÀíʹÓà $_SERVER["SERVER_NAME"] ºÍ $_SERVER["HTTP_HOST"]¡£
²Î¿¼£º
Nginx Rewrite Flags
* last Ï൱ÓÚApacheÀïµÄ[L]±ê¼Ç£¬±íʾÍê³Érewrite
* break ÖÕֹƥÅä, ²»ÔÙÆ¥ÅäºóÃæµÄ¹æÔò
* redirect ·µ»Ø302ÁÙʱÖض¨Ïò
* permanent ·µ»Ø301ÓÀ¾ÃÖض¨Ïò
NginxÕýÔò±í´ïʽƥÅä
* ~ ΪÇø·Ö´óСдƥÅä
* ~* Ϊ²»Çø·Ö´óСдƥÅä
* !~ºÍ!~*·Ö±ðΪÇø·Ö´óСд²»Æ¥Åä¼°²»Çø·Ö´óСд²»Æ¥Åä
NginxÎļþ¼°Ä¿Â¼Æ¥Åä
* -fºÍ!-fÓÃÀ´ÅжÏÊÇ·ñ´æÔÚÎļþ
* -dºÍ!-dÓÃÀ´ÅжÏÊÇ·ñ´æÔÚĿ¼
* -eºÍ!-eÓÃÀ´ÅжÏÊÇ·ñ´æÔÚÎļþ»òĿ¼
* -xºÍ!-xÓÃÀ´ÅжÏÎļþÊÇ·ñ¿ÉÖ´ÐÐ
NginxÈ«¾Ö±äÁ¿
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ