nginx動靜分離之後,設定預設主頁
阿新 • • 發佈:2018-11-20
nginx動靜分離之後,設定預設主頁
預設情況下,配置nginx動靜分離之後,預設location / 是到後端,不能設定前段頁面為預設主頁。需如下配置
upstream abc { server 172.16.3.20:9000 weight=1 max_fails=2 fail_timeout=10s; server 172.16.3.21:9000 weight=1 max_fails=2 fail_timeout=10s; ip_hash; } server { listen 443; server_name www.abc.com; access_log /usr/local/nginx/log/www.abc.com.access.log main; error_log /usr/local/nginx/log/www.abc.com.error.log warn; error_page 500 502 503 504 = /50x.html; ssl on; ssl_certificate /usr/local/ssl/xxx.pem; ssl_certificate_key /usr/local/ssl/xxx.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH:!kEDH:!kECDH; ssl_prefer_server_ciphers on; location ~ \.(html|htm|gif|jpeg|jpg|css|js|png|swf|ico)$ { root /usr/local/abc; index index.html index.htm; } location / { proxy_pass http://abc; include /usr/local/nginx/conf/conf.d/proxy.conf; } location ~ ^/$ { #將/限制出來 root /usr/local/abc; } } server { listen 80; server_name www.abc.com; access_log /usr/local/nginx/log/www.abc.com.access.log main; error_log /usr/local/nginx/log/www.abc.com.error.log warn; location / { return 301 https://www.abc.com; } }
proxy.conf配置為
#proxy.conf proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect http:// $scheme://; proxy_set_header X-Forwarded-Proto https; add_header Front-End-Https on; proxy_redirect off; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_headers_hash_max_size 51200; proxy_headers_hash_bucket_size 6400;