#配置Nginx動靜分離,定義的靜態頁面直接從Nginx發佈目錄讀取。 location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css|mp4|mp3|avi)$ { root /web/www; #expires定義用戶瀏覽器緩存的時間爲7天,如果靜態頁面不常更新,可以設置更長,這樣可以節省帶寬和緩解服務器的壓力 expires 7d; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # location ~ \.php$ { proxy_pass http://127.0.0.1:8080; }
修改後可以先檢查一下配置文件是否有錯誤 ./nginx -t -c $PATH; $PATH 是nginx配置文件的絕對路徑, 如果不用 -c路徑參數, 默認是 /usr/local/nginx/conf/nginx.conf 然後重新加載配置文件 ./nginx -s -c $PATH reload;