Nginx服務(wù)器中瀏覽器本地緩存和虛擬機(jī)的相關(guān)設(shè)置
自動(dòng)列出目錄配置:
下載過開源軟件的都知道,一個(gè)很簡(jiǎn)單的頁面列出了所有版本的源碼包,這就是開啟了自動(dòng)列出目錄
如下配置,在虛擬主機(jī)location / {……}目錄控制中配置自動(dòng)列出目錄:
location / {
autoindex on;
}
瀏覽器本地緩存設(shè)置:
瀏覽器是為了加速瀏覽,瀏覽器在用戶磁盤上對(duì)最近請(qǐng)求過的文件進(jìn)行存儲(chǔ),當(dāng)訪問者再次請(qǐng)求這個(gè)頁面,
瀏覽器可以從本地磁盤顯示文件,以達(dá)到加速瀏覽的效果,節(jié)約了網(wǎng)絡(luò)資源,提高了網(wǎng)絡(luò)效率
關(guān)鍵字: expires
默認(rèn)值: off
作用域: http,server.location
用途: 通過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)單一句話說就是不同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配置文件nginx.conf常用參數(shù)中文詳解
這篇文章主要介紹了比較完整的Nginx配置文件nginx.conf常用參數(shù)中文詳解,需要的朋友可以參考下2015-07-07
Nginx+Tomcat反向代理與負(fù)載均衡的實(shí)現(xiàn)
這篇文章給大家詳細(xì)介紹了如何實(shí)現(xiàn)Nginx+Tomcat反向代理與負(fù)載均衡,文中的流程步驟介紹的非常詳細(xì)對(duì)我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-07-07
nginx容器配置文件獨(dú)立的實(shí)現(xiàn)
本文主要介紹了nginx容器配置文件獨(dú)立,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
nginx?80端口配置多個(gè)location無效訪問404問題
這篇文章主要介紹了nginx?80端口配置多個(gè)location無效訪問404問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
Nginx服務(wù)器中l(wèi)ocation配置的一些基本要點(diǎn)解析
這篇文章主要介紹了Nginx服務(wù)器中l(wèi)ocation配置的一些基本要點(diǎn)解析,特別對(duì)管理以及查找匹配作出了詳細(xì)的講解,需要的朋友可以參考下2015-12-12
Nginx日志實(shí)現(xiàn)訪問異常報(bào)警詳解
Nginx把遇到的不同級(jí)別的問題信息寫到錯(cuò)誤日志。error_log 指令配置記錄到特定的文件,stderr,或者syslog,配置寫到日志的最低級(jí)別信息。下面這篇文章主要介紹了利用Nginx日志實(shí)現(xiàn)訪問異常報(bào)警的相關(guān)資料,需要的朋友可以參考下。2017-03-03

