worker_processes auto;
worker_cpu_affinity auto; 
worker_rlimit_nofile 65535;

events {
    worker_connections 8192;
	use epoll; 
	multi_accept on;
	accept_mutex off;  
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
	tcp_nopush      on;
	tcp_nodelay     on;
    keepalive_timeout  65;
	client_max_body_size 60m;
	proxy_connect_timeout 15s;
    proxy_read_timeout 120s;

	gzip on;
	gzip_min_length 1k;
	gzip_comp_level 9;
	gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
	gzip_vary on;
	gzip_disable "MSIE [1-6]\.";
	
	server {
		listen 443 ssl http2;  
		server_name bqxm.alafarms.com;
	 
		root html;
		index index.html index.htm;
		ssl_certificate /usr/local/nginx/jks/bqxm.alafarms.com.pem;
		ssl_certificate_key /usr/local/nginx/jks/bqxm.alafarms.com.key;
		ssl_session_timeout 5m;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
		ssl_prefer_server_ciphers on;

        # ====================== SPA 静态资源规则 ======================
        # 部署目录：/opt/page/bqH5/、/opt/page/bqjy/ ...
        # 1. /xxx/assets/ 优先匹配，找不到就 404，禁止 fallback 成 index.html
        # 2. index.html 禁止缓存（防 iOS 微信缓存旧入口）
        # 3. 其它 .js/.css 等静态文件同样 404，不回 HTML
        # 4. 仅前端路由才 fallback 到 index.html
        # ======================================================
		
		# 页面1 bqH5（uni-app 移动端 H5）
		location ^~ /bqH5/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /bqH5/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/bqH5/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /bqH5/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /bqH5/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 页面2 bqjy
		location ^~ /bqjy/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /bqjy/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/bqjy/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /bqjy/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /bqjy/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 页面3 client
		location ^~ /client/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /client/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/client/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /client/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /client/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 页面4 screen
		location ^~ /screen/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /screen/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/screen/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /screen/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /screen/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 页面5 shopClient
		location ^~ /shopClient/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /shopClient/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/shopClient/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /shopClient/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /shopClient/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 页面6 bqShop
		location ^~ /bqShop/assets/ {
			root /opt/page;
			try_files $uri =404;
			expires 1y;
			add_header Cache-Control "public, immutable";
			access_log off;
		}
		location = /bqShop/index.html {
			root /opt/page;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
			add_header Pragma "no-cache";
			add_header Expires "0";
		}
		location ~* ^/bqShop/.+\.(js|mjs|css|png|jpg|jpeg|svg|ico|woff|woff2|ttf|map)$ {
			root /opt/page;
			try_files $uri =404;
			expires 7d;
			add_header Cache-Control "public, max-age=604800";
		}
		location /bqShop/ {
			root /opt/page;
			index index.html index.htm;
			try_files $uri $uri/ /bqShop/index.html;
			add_header Cache-Control "no-cache, no-store, must-revalidate";
		}
		
		# 上传图片
		location /profile/ {
			alias  /home/baqing/uploadPath/;
			expires 30d;
		}
		
		# 后端接口
		location /prod-api/ {
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://localhost:8010/;
		}
		
		location /shop-api/ {
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://localhost:8020/;
		}
		
		# gis
		location /agis-api/ {
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_pass http://192.168.136.240:7103/;
		}
		
		error_page   500 502 503 504  /50x.html;
		location = /50x.html {
				root   html;
		}
		
   }
}
