nginx 使用 unicron 将 https 添加到 nginx 并重定向 https 默认

nginx 使用 unicron 将 https 添加到 nginx 并重定向 https 默认

下面我添加了我的 nginx.conf 文件,如何将 https 添加到此 nginx 服务器并默认重定向到 https。我的 crt 和密钥文件位于 /home/ubuntu/ssl/ 文件夹中

worker_processes 1;
user nobody nogroup;

pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  # Set this to on if you have more than 1 working processes
  # This will allow only one child to watch the pollset and accept
  # a connection to a socket
  accept_mutex off; # "on" if nginx worker_processes > 1
}

http {
  include mime.types;
  default_type application/octet-stream;
  access_log /tmp/nginx.access.log combined;

  # This tells Nginx to ignore the contents of a file it is sending
  # and uses the kernel sendfile instead
  sendfile on;

  # Set this to on if you have sendfile on
  # It will prepend the HTTP response headers before
  # calling sendfile()
  tcp_nopush on;

  # This disables the "Nagle buffering algorithm" (Nginx Docs)
  # Good for websites that send a lot of small requests that
  # don't need a response
  tcp_nodelay off;

  gzip on;
  gzip_http_version 1.0;
  gzip_proxied any;
  gzip_min_length 500;
  gzip_disable "MSIE [1-6]\.";
  gzip_types text/plain text/html text/xml text/css
             text/comma-separated-values
             text/javascript application/x-javascript
             application/atom+xml;

  upstream unicorn_server {
   # This is the socket we configured in unicorn.rb
   server unix:/home/ubuntu/domain/webapp/domain/tmp/sockets/unicorn.sock
   fail_timeout=0;
  }

  server {
    listen 8080;
    client_max_body_size 4G;
    server_name _;

    keepalive_timeout 5;

    # Location of our static files
    root /home/ubuntu/domain/webapp/domain/public;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;

      # If you don't find the filename in the static files
      # Then request it from the unicorn server
      if (!-f $request_filename) {
        proxy_pass http://unicorn_server;
        break;
      }

    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /home/ubuntu/domain/webapp/domain/public;
    }
  }
}

我已经使用过这个代码

 server {
listen 443 default;

ssl on;
ssl_certificate    /home/ubuntu/ssl/7e4929e438d0d6f1.crt;
ssl_certificate_key     /home/ubuntu/ssl/domain.key;

server_name _;
 # Location of our static files
 root /home/ubuntu/domain/webapp/domain/public;


location / {
  proxy_redirect off;
  proxy_set_header X-Forwarded-Proto https;
  proxy_pass http://unicorn_server;
}
  error_page 500 502 503 504 /500.html;
location = /500.html {
  root /home/ubuntu/doamin/webapp/domain/public;
keepalive_timeout 5;
}

但什么也没有发生。

答案1

server {
       listen         80;
       server_name    yourhostname;
       return         301 https://$server_name$request_uri;
}

关于 SF 有很多问题。以下是其中一个他们

相关内容