續:nginx安裝配置css
同時解開http模塊以下部分註釋html
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main;
1.12.1版本須要手動在 nginx/1.12.1/目錄下新建logs目錄。啓動能夠自動生成access.log文件。nginx
另外能夠針對具體 server 生成日誌文件,server 模塊中加入以下配置:緩存
error_log logs/error_8888.log error; access_log logs/access_8888.log main;
配置文件加載順序:nginx.conf --> conf.d/*.conf
文件 conf.d/*.conf 中內容是 server 模塊
修改配置文件 conf.d/XXX.conf 服務器
# server 1 server { listen 8888;# 監聽8888端口 server_name localhost;# 監聽服務器 #charset koi8-r; #access_log logs/host.access.log main; error_log logs/error_8888.log error; access_log logs/access_8888.log main; location / {# 「/」 攔截全部http://localhost:8888/請求 proxy_pass http://127.0.0.1:8080/; # 全部到http://localhost:8888/請求反向代理轉向目標地址http://127.0.0.1:8080/ proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Firwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
服務路徑攜帶別名ide
# server 1 server { listen 8888;# 監聽8888端口 server_name localhost;# 監聽服務器 #charset koi8-r; #access_log logs/host.access.log main; error_log logs/error_8888.log error; access_log logs/access_8888.log main; location /guaguale/ {# 攔截全部http://localhost:8888/guaguale/請求 proxy_pass http://127.0.0.1:8080/guaguale/; # 全部到http://localhost:8888/guaguale/請求反向代理轉向目標地址http://127.0.0.1:8080/guaguale/ proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Firwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; } # 請求異常500 502 503 504 轉向地址 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; # 設置資源根路徑 } }
建立新文件 conf.d/YYY.conf,新建 server 模塊,具體配置相似上面server。3d
# server 2 server { listen 9999;# 監聽9999端口 server_name localhost;# 監聽服務器 error_log logs/error_9999.log error; access_log logs/access_9999.log main; location /heimdall/ {# 攔截全部http://localhost:9999/heimdall/請求 proxy_pass http://127.0.0.1:8181/heimdall/;# 全部到http://localhost:9999/heimdall/請求反向代理轉向目標地址http://127.0.0.1:8181/heimdall/ proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Firwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; } }
一樣道理能夠作靜態資源分離。代理
server { listen 80; server_name localhost; # static file location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|js|css)$ { # 正則校驗過濾 root /usr/share/nginx/html; # 設置靜態資源根路徑地址 #cache 緩存失效時間 expires 3d; } }