Nnginx 多域名 匹配專案配置
阿新 • • 發佈:2019-01-07
很簡單的配置,不多說。
先看nginx.conf
user nginx; worker_processes 4; worker_cpu_affinity 00000001 00000010 00000100 00001000; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { use epoll; worker_connections 65535; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; log_format main_upstream '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$upstream_addr $upstream_status $upstream_response_time"'; access_log /var/log/nginx/access.log; client_max_body_size 500m; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; gzip_types text/plain application/x-javascript application/javascript text/css application/xml; #拒絕IP直接訪問 server { listen 80 default; server_name _; return 403; } #每個專案配置負載均衡,便於擴充套件 upstream insurance_front { server 127.0.0.1:6666 weight=1; } upstream insurance_admin { server 127.0.0.1:7777 weight=1; } upstream insurance_service { server 127.0.0.1:8888 weight=1; } #每個專案的詳細配置,通過引入的方式, 便於管理 include /etc/nginx/conf.d/*.conf; }
拿出其中一個專案配置展示
server { listen 80; server_name www.***.com *****.com; location / { root /data/project/static-resources/; index index.html index.htm; #access_log /var/log/nginx/insurance-mall.access.log main_upstream; #error_log /var/log/nginx/insurance-mall.error.log error; } location ~* (\.shtml|\.jsp|\.jspf) { #動態通過叢集代理 proxy_pass http://insurance_front; proxy_set_header X-real-ip $remote_addr; proxy_set_header Host $http_host; #proxy_cache_valid 200 304 12h; #proxy_cache_key $host$uri$is_args$args; #access_log /var/log/nginx/insurance-server.access.log main_upstream; #error_log /var/log/nginx/insurance-server.error.log error; } #靜態資源 location ~* .(gif|jpg|jpeg|png|js|css|htm|html)$ { root /data/project/static-resources/; } #靜態快取 location ~* .(gif|jpg|jpeg|png|css|htm|html)$ { expires 14d; } location ^~ /WEB-INF { deny all; } error_page 403 404 /404.html; location = /404.html { root /usr/share/nginx/html; } location = /favicon.ico { log_not_found off; access_log off; } }