Назад | Перейти на главную страницу

nginx с unicron добавляет https в nginx и перенаправляет https по умолчанию

Ниже я добавил свой файл nginx.conf, как добавить https на этот сервер nginx и перенаправить на https по умолчанию. Мои файлы crt и key находятся в папке / 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;
}

Но ничего не происходит.

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

По НФ есть много вопросов. Вот один из их.