我已经设置了一个nginx的反向代理来服务我的前端通过端口80,然后被redirect到443 ssl https和我的api后端节点 – expression在端口5000 over / api上。 到目前为止的基本工作,除了我不能通过json-web-token进行身份validation。 我总是得到一个“未经授权的”。
尝试通过邮递员和access_token是100%正确的。
对不起,如果这个问题之前已经被问过了(已经search了几天),但是这个话题对我来说是非常新的,我不想在涉及安全问题时做一些事情。
我的nginxconfiguration看起来像这样
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; return 301 https://$host$request_uri; } # HTTPS — proxy all requests to the Node app server { # Enable HTTP/2 listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name example.com; root /var/www/example.com/html; location / { auth_basic "Restricted"; auth_basic_user_file /var/www/example.com/.htpasswd; try_files $uri $uri/ /index.html; } location /api { 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_pass http://127.0.0.1:5000; } # Use the Let's Encrypt certificates ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # Include the SSL configuration from cipherli.st include snippets/ssl-params.conf; }
所以我的问题是:
1.)我在这里改变什么,所以我的jwt令牌得到成功转移通过api后端? 2.)我需要明确启用https在我的后端服务器上吗?
谢谢!!
发现问题 – json web令牌在variables名称中包含下划线–nginx删除整个variables。
固定:
underscores_in_headers on;