0
私は、ubuntu 14.04とnginxを使用して、デジタル海洋サーバーでアプリケーションを実行しています。私のアプリはgunicornを介して実行されます。 httpリクエストを直接httpsにリダイレクトしたいと思います。 試しましたnginxサーバのhttpsへのHTTPリクエストのリダイレクト
server {
# Running port
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
サファリで動作します。しかし、それはクロームやFirefoxで動作しませんか?私が間違って何を考えている? は私が
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
sendfile on;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 5;
gzip_proxied any;
gzip_min_length 256;
gzip_vary on;
# Configuration containing list of application servers
upstream app_servers {
server 127.0.0.1:8080;
}
# Configuration for Nginx
server {
# Running port
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
# Settings to serve static files
location /static/ {
# Example:
# root /full/path/to/application/static/file/dir;
root /var/www/example/app/;
location ~* \.(jpg|woff|jpeg|png|gif|ico|css)$ {
expires 30d;
}
location ~* \.(js)$ {
expires 1d;
}
# we do not cache html, xml or json
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}
location ~* \.(pdf)$ {
expires 30d;
}
}
# Serve a static file (ex. favico)
# outside /static directory
location = /favico.ico {
root /app/favico.ico;
gzip_static on;
}
}
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/ssl/certs/dhparam.pem;
# Proxy connections to the application servers
# app_servers
location/{
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_pass http://app_servers;
proxy_redirect off;
# proxy_redirect http:// https://;
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-Host $server_name;
}
}
}
okだから、静的なものをlistenすることをお勧めします。私はそれを試みましたが、それでも私が望むことはしません。それはhttpとhttpsを提供しますが、私は常にhttpsにリダイレクトしたいと思います... – carl
このディスカッションルームに参加してくださいhttps://chat.stackoverflow.com/rooms/152957/edirect-http-request-to-https-on-nginx -サーバ –