【匯總】nginx【php,location,alias,504】
?? 安裝
#tar -zxvf nginx-1.0.5.tar.gz#cd nginx-1.0.5#./configure --prefix=/usr/local/nginx#make#make install
?
?
?? 啟動
// 啟動#/usr/local/nginx/sbin/nginx// 重啟#/usr/local/nginx/sbin/nginx -s reload#/usr/local/nginx/sbin/nginx -s reopen
?
?
?? 配置1 - PHP(fastcgi安裝)
?? 配置2 - Alias
....http { .... server { .... # http://.../a/ location /a/ { alias /var/www/a/; } # http://.../a/*.php location ~ /a/.+\.php$ { rewrite /a/(.+\.php) /$1 break; alias /var/www/a/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # http://.../ location / { alias /var/www/root/; } # http://.../*.php location ~* \.(php)$ { alias /var/www/root/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }}?
?
?? 關於alias中使用rewrite的必要性:
?? 引用網址:http://www.pppei.net/blog/post/133
?
?
?? 關於nginx的location規則
?? 引用網址:https://wangyan.org/blog/nginx-location.html
location [=|~|~*|^~|@] /uri/ { … }
〖=〗 表示精確匹配,如果找到,立即停止搜尋並立即處理此請求。〖~〗 表示區分大小寫匹配〖~*〗 表示不區分大小寫匹配〖^~〗 表示只匹配字串,不查詢Regex。〖@〗 指定一個命名的location,一般只用於內部重新導向請求。
?? 配置執行個體
location = / { # 只匹配對 / 目錄的查詢. [ config A ]}location / { # 匹配以 / 開始的查詢,即所有查詢都匹配。 [ config B ]}location ^~ /images/ { # 匹配以 /images/ 開始的查詢,不再檢查Regex。 [ config C ]}location ~* \.(gif|jpg|jpeg)$ { # 匹配以gif, jpg, or jpeg結尾的檔案,但優先順序低於config C。 [ config D ]}?
?
?? 解決nginx 504 Gateway Time-out的一些方法
?? 引用網址:http://blog.csdn.net/tengzhaorong/article/details/5814905
fastcgi_buffers 2 256k;fastcgi_buffer_size 128K;fastcgi_busy_buffers_size 256K;fastcgi_temp_file_write_size 256K;
?? 註:本機測試並不顯著,有時間附上配置說明
?