英文:
Is there a way to make a https post with only port 80 in nginx config file?
问题
So, I have a Django app which needs to send data to an API.
I am using request to send the data.
First, it was warning me that -in short- I am not using SSL for sending the JSON data.
To solve this I added "verify=PATH TO THE CERT FILE".
requests.post(url, json=payload, verify='\fullChainCert.crt')
After this I got 200, so I was happy.
Question is, will it work like this on server?
Port 443 is open on server, but only 80 in nginx config file.
英文:
So, I a have Django app which needs to send data to an API.
I am using request to send the data.
First, it was warning me that -in short- I am not using SSL for sending the JSON data.
To solve this I added "verify=PATH TO THE CERT FILE"
requests.post(url, json=payload, verify='\fullChainCert.crt')
After this I got 200, so I was happy.
Question is, will it work like this on server?
Port 443 is open on server, but only 80 in nginx config file.
答案1
得分: 0
你可以配置 nginx.conf
文件以使用 443 端口进行 https,并将流量从 80 端口重定向到 443 端口。一个简单的 https 配置如下:
server {
listen 80;
server_name yourservername.com 或 your_public_ip;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name yourservername.com 或 your_public_ip;
# 你应该创建 SSL 证书并在这里使用它们
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_dhparam /etc/ssl /certs/dhparam.pem;
location / {
proxy_pass http://django_app;
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;
}
}
英文:
You can configure the nginx.conf
file to work with https 443 port and redirect traffic coming to port 80 to port 443. A simple https configuration looks like this:
server {
listen 80;
server_name yourservername.com or your_public_ip;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name yourservername.com or your_public_ip;
# You should create the ssl certificates and use them here
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_dhparam /etc/ssl /certs/dhparam.pem;
location / {
proxy_pass http://django_app;
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;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论