Nginx Implementation https Website Configuration Code Example

  • 2021-09-11 21:51:33
  • OfStack

https Basic Port 443. Used for a thing called a key. Don't think you can realize these things without understanding them. Impossible.

1. The key is generated first. Let's generate it directly under linux and assume that the nginx directory is/usr/local/nginx-1. 2.9

Next

cd /usr/local/nginx-1.2.9/conf/;
mkdir ssl;
cd ssl;
# Let's start creating the key. If you're not familiar with it, you don't have to pay attention to why you're doing it. Just do it
openssl genrsa-des3-out server. key 1024; # This 1 step will let you enter your password. Just enter it. This password will be used in the following step. Feel free
openssl req-new-key server. key-out server. csr; # Enter the password just set and enter one way
cp server.key server.key.org;
openssl rsa-in server. key. org-out server. key; # This 1 step also requires a password
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt;
# At the end of this build, there are several files under server. crt server. csr server. key server. key. org in the ssl directory

2. Step 2, let's build a site. The configuration file is as follows. (If you can't write the configuration file, you can refer to this forum.)


server {
  listen    443;
  ssl on;
# Pay attention to the path and file extension 
  ssl_certificate /usr/local/nginx-1.2.9/conf/ssl/server.crt;
  ssl_certificate_key /usr/local/nginx-1.2.9/conf/ssl/server.key;
  server_name  Domain name ;
  root   Website Root Directory ;
  location / {
    index index.html index.php;
  }
# Support PHP
  location ~ \.php{
    include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
  }
}

Okay nginx-s reload Restart nginx See 1. You can use https to access


Related articles: