将HTTP重定向到HTTPS会丢失数据?

时间:2018-06-24 09:48:32

标签: rest http nginx reverse-proxy nginx-reverse-proxy

我使用certbot为我的域创建一个SSL证书。它自动修改了我的Nginx配置。以下是将http(80)重定向到https(443)的部分:

server {
if ($host = domain.tld) {
    return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.domain.tld) {
    return 301 https://$host$request_uri;
} # managed by Certbot

    listen 80 default_server;
    listen [::]:80 default_server;
    server_name www.suzaku.pw suzaku.pw;
    return 404;
}

这似乎可行。但是问题在于,任何POST / PUT / DELETE请求现在都被解释为GET请求:

http://domain.tld/api仅了解GET

https://domain.tld/api适用于所有GET / POST / PUT / DELETE

_

下面是配置的其余部分(HTTP被转发到其中)

server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name www.domain.tld domain.tld;
location / { try_files $uri $uri/ =404; }
location ~ \.php$ { ... }
listen [::]:443 ssl http2 default_server ipv6only=on; # managed by Certbot
listen 443 ssl http2 default_server; # managed by Certbot
ssl on;
ssl_certificate /etc/letsencrypt/live/www.domain.tld/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.domain.tld/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location ^~ /jenkins/ { ... }
location ^~ /api {
    proxy_pass http://localhost:6000;
    proxy_http_version 1.1;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-Proto https;
    proxy_set_header  X-Forwarded-For $remote_addr;
    proxy_set_header  X-Forwarded-Host $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
}

我的配置中是否有任何明显的错误?

0 个答案:

没有答案