Nginx服務(wù)器中瀏覽器本地緩存和虛擬機(jī)的相關(guān)設(shè)置
自動(dòng)列出目錄配置:
下載過(guò)開源軟件的都知道,一個(gè)很簡(jiǎn)單的頁(yè)面列出了所有版本的源碼包,這就是開啟了自動(dòng)列出目錄
如下配置,在虛擬主機(jī)location / {……}目錄控制中配置自動(dòng)列出目錄:
location / { autoindex on; }
瀏覽器本地緩存設(shè)置:
瀏覽器是為了加速瀏覽,瀏覽器在用戶磁盤上對(duì)最近請(qǐng)求過(guò)的文件進(jìn)行存儲(chǔ),當(dāng)訪問(wèn)者再次請(qǐng)求這個(gè)頁(yè)面,
瀏覽器可以從本地磁盤顯示文件,以達(dá)到加速瀏覽的效果,節(jié)約了網(wǎng)絡(luò)資源,提高了網(wǎng)絡(luò)效率
關(guān)鍵字: expires
默認(rèn)值: off
作用域: http,server.location
用途: 通過(guò)expires指令控制http應(yīng)答中的”Expires”和”Cache-Control”的頭信息
配置項(xiàng):
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; }
配置虛擬主機(jī):
nginx可以配置多種類型的虛擬主機(jī),基于ip的 基于域名的 基于端口的,
簡(jiǎn)單一句話說(shuō)就是不同ip相同端口,不同端口相同ip or域名,不同域名相同端口
下面是基于相同域名的虛擬主機(jī)配置文件:
server { listen 80 default; server_name www.wpython.com; index index.html index.htm index.php; root /alidata/www/www.wpython.com; # wordpress 偽靜態(tài)規(guī)則 location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /alidata/log/nginx/access/www.wpython.com.log; } server { listen 80 default; server_name www.pyyw.net; index index.html index.htm index.php; root /alidata/www/www.pyyw.net; # wordpress 偽靜態(tài)規(guī)則 location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } rewrite /wp-admin$ $scheme://$host$uri/ permanent; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } access_log /alidata/log/nginx/access/www.pyyw.net.log; }
相關(guān)文章
Nginx實(shí)現(xiàn)跨域使用字體文件的配置詳解
這篇文章主要給大家介紹了關(guān)于Nginx實(shí)現(xiàn)跨域使用字體文件的配置方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-06-06Python的Bottle框架基本知識(shí)總結(jié)
這篇文章主要介紹了Python的Bottle框架基本知識(shí)總結(jié),本文翻譯自Bottle官方開發(fā)文檔,需要的朋友可以參考下2015-05-05詳解 Nginx 負(fù)載均衡和反向代理配置和優(yōu)化
這篇文章主要介紹了詳解 Nginx 負(fù)載均衡和反向代理配置和優(yōu)化的相關(guān)資料,需要的朋友可以參考下2017-03-03配置Nginx出現(xiàn)403(Forbidden)靜態(tài)文件加載不出來(lái)的解決方法
本文主要介紹了配置Nginx出現(xiàn)403(Forbidden)靜態(tài)文件加載不出來(lái)的解決方法,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-12-12nginx 負(fù)載均衡 多站點(diǎn)共享Session
這里我們就 演練一下 以數(shù)據(jù)庫(kù)的形來(lái)存儲(chǔ)Session,來(lái)實(shí)現(xiàn)多站點(diǎn)共享Session2012-11-11