nginxÔõÑù¿ªÆôα¾²Ì¬
ÔõÑù¿ªÆô nginx α¾²Ì¬£¿ÆôÓà multiviews Ä£¿é£¬ÔÊÐíЧÀÍÆ÷ƾ֤À©Õ¹ÃûËÑË÷Îļþ¡£Ìí¼Óα¾²Ì¬¹æÔò£¬½« .php url ÖØдµ½Æ¥ÅäµÄ php Îļþ¡£È·±£ web ЧÀÍÆ÷Àú³ÌÓÐȨ»á¼û php Îļþ¡£ÖØÆô nginx ÒÔÓ¦Óøü¸Ä£¬´Ó¶øʵÏÖ url Ó³Éäµ½Îļþ·¾¶µÄ¹¦Ð§¡£
ÔõÑù¿ªÆô Nginx α¾²Ì¬
Nginx α¾²Ì¬ÊÇÒ»ÖÖÉèÖÃÒªÁ죬ÔÊÐíЧÀÍÆ÷½« URL Ó³Éäµ½ÄÚ²¿Îļþϵͳ·¾¶£¬´Ó¶øʵÏÖÀàËÆÓÚ Apache .htaccess ÖÐ Rewrite Ä£¿éµÄ¹¦Ð§¡£¿ªÆô Nginx α¾²Ì¬ºÜ¼òÆÓ£¬Ö»ÐèÒÔÏ°취£º
1. ÆôÓÃ MultiViews
Ê×ÏÈ£¬ÔÚ Nginx ÉèÖÃÎļþÖÐÆôÓà MultiViews Ä£¿é£º
server { ... location / { autoindex on; multiviews on; } ... }
µÇ¼ºó¸´ÖÆ
2. ÉèÖÃα¾²Ì¬¹æÔò
ÔÚÏàͬµÄλÖÿéÖУ¬Ìí¼ÓÒÔÏÂα¾²Ì¬¹æÔò£º
location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
µÇ¼ºó¸´ÖÆ
3. ÐÞ¸ÄÎļþȨÏÞ
È·±£ Web ЧÀÍÆ÷Àú³ÌÓÐȨ»á¼ûÄúµÄ PHP Îļþ¡£Îª´Ë£¬ÇëʹÓÃÒÔÏÂÏÂÁ
sudo chmod 644 /var/www/html/*.php
µÇ¼ºó¸´ÖÆ
4. ÖØÆô Nginx
×îºó£¬ÖØÆô Nginx ÒÔÓ¦Óøü¸Ä£º
sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
ÔÀí˵Ã÷£º
ͨ¹ýÆôÓà MultiViews Ä£¿é£¬Nginx ÔÊÐíЧÀÍÆ÷ƾ֤ÇëÇóµÄÎļþÀ©Õ¹ÃûËÑË÷¶à¸öÎļþ¡£Î±¾²Ì¬¹æÔò½«ËùÓÐÒÔ .php ×îºóµÄ URL ÖØдµ½Óë֮ƥÅäµÄ PHP Îļþ¡£µ±ÇëÇó´¦Öóͷ£Ê±£¬Nginx ½« PHP Îļþת´ï¸ø FastCGI ´¦Öóͷ£³ÌÐò£¬FastCGI ´¦Öóͷ£³ÌÐòÈ»ºóÖ´ÐÐ PHP ´úÂë²¢ÌìÉúÏìÓ¦¡£
ÒÔÉϾÍÊÇnginxÔõÑù¿ªÆôα¾²Ì¬µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡