本文共 3141 字,大约阅读时间需要 10 分钟。
Nginx配置说明:后台路由网关映射路径设置
在项目中进行Nginx后台路由网关映射路径配置时,我们采用了三个独立的网关分别对应管理平台、APP端以及设备端。这些网关的证书配置已经预先设置在SLB中,因此Nginx本身无需处理证书相关配置。如需了解Nginx证书配置方法,建议参考其他技术文档。
以下是Nginx的具体配置内容:
# 用户信息设置user nobody;worker_processes 1;# 日志设置(已注释,实际配置可根据需要调整)#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;# PID文件设置#pid logs/nginx.pid;# 事件处理events { worker_connections 1024;}# MIME类型默认设置include 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"';# 访问日志设置(已注释,实际配置可根据需要调整)#access_log logs/access.log main;# 传输文件和连接优化设置sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 10m;types_hash_max_size 2048;# Gzip压缩设置#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 80; server_name localhost; # 传输文件大小限制 client_max_body_size 550M; client_header_timeout 20m; client_body_timeout 20m; proxy_connect_timeout 1500s; proxy_read_timeout 20m; proxy_send_timeout 20m; # 证书配置已注释,实际部署需重新配置 #ssl_certificate /usr/local/nginx/conf/certs/next1.galanz.com.cn.pem; #ssl_certificate_key /usr/local/nginx/conf/certs/next1.galanz.com.cn.key; #ssl_session_cache shared:SSL:1m; #ssl_session_timeout 5m; #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #ssl_prefer_server_ciphers on; # 配置underscores在头信息中 underscores_in_headers on; # 设置代理相关头信息 proxy_set_header Host $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_set_header X-Forwarded-Proto $scheme; # 路由规则设置 location ^~ /admin/ { proxy_pass http://admin/; } location ^~ /app/ { proxy_pass http://app/; } location ^~ /device/ { proxy_pass http://device/; } # 静态资源和默认页面设置 location / { root html/dist; try_files $uri /index.html; index index.html index.htm; } # 特定路径配置 location ^~ /.well-known { allow all; } location ^~ /apps/galanz { # 移动端链接处理 if ($http_user_agent ~* "iphone") { rewrite ^(.*)$ https://apps.apple.com/cn/app/%E6%A0%BC%E5%85%B0%E4%BB%95%E7%BE%8E%E9%A3%9F/id1531040880; } # 其他移动设备自动跳转 if ($http_user_agent ~* "(mobile|nokia|android|samsung|htc|blackberry)") { rewrite ^(.*)$ https://app.galanz.com.cn/galanz; } } location ^~ /support/after { rewrite ^(.*)$ https://www.galanz.com.cn/?page_id=1638; } location ^~ /galanz/ { alias html/galanz/; }}# 包含额外的IP白名单配置文件include blockip.conf; 以上就是关于Nginx后台路由网关映射路径配置的详细说明。通过上述配置,我们实现了对管理平台、APP端以及设备端的路由网关映射设置。配置中未涉及证书设置部分,可根据实际需求在相应位置重新配置。希望以上内容能为您的项目提供参考价值。
转载地址:http://zujfk.baihongyu.com/