Nginx implements https website configuration code example

Nginx implements https website configuration code example

https base port 443. It is used for something called a key. Don't think you can do it without understanding these things. It's impossible.

1. Generate the key first. Let's generate it directly under Linux, assuming that the nginx directory is /usr/local/nginx-1.2.9

Next Steps

cd /usr/local/nginx-1.2.9/conf/;
mkdir ssl;
cd ssl;
# Now start creating the key. If you are not familiar with it, just follow the instructions without worrying about why you are doing this.
openssl genrsa -des3 -out server.key 1024;#This step will ask you to enter a password. Just enter it. The following step will use this password. Feel free to
openssl req -new -key server.key -out server.csr;#Enter the password you just set and press Enter
cp server.key server.key.org;
openssl rsa -in server.key.org -out server.key;#This step also requires a password
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt;
#Generation is complete. There are several files in the ssl directory: server.crt server.csr server.key server.key.org

2. In the second step, let's build a site. The configuration file is as follows. (If you don't know how to write a configuration file, you can refer to this forum)

server {
  listen 443;
  ssl on;
#Note 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;
  }
}

OK, restart nginx with nginx -s reload and see. You can access it using https

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example of how to configure nginx to implement SSL
  • Detailed tutorial on configuring nginx for https encrypted access
  • Implementation of Nginx domain name forwarding https access
  • Alibaba Cloud Nginx configures https to implement domain name access project (graphic tutorial)
  • Detailed explanation of the principle and implementation process of Nginx configuration https
  • Nginx configures the same domain name to support both http and https access
  • Detailed configuration of Nginx supporting both Http and Https
  • Implementation of HTTP and HTTPS services with Nginx reverse proxy for multiple domain names
  • Example code for using Nginx to implement 301 redirect to https root domain name
  • How to change the website accessed by http to https in nginx

<<:  Javascript to achieve the drag effect of the login box

>>:  Html easily implements rounded rectangle

Recommend

Analysis of the principles of Mysql dirty page flush and shrinking table space

mysql dirty pages Due to the WAL mechanism, when ...

Nine advanced methods for deduplicating JS arrays (proven and effective)

Preface The general methods are not listed here, ...

Nest.js authorization verification method example

Table of contents 0x0 Introduction 0x1 RBAC Imple...

7 Ways to Write a Vue v-for Loop

Table of contents 1. Always use key in v-for loop...

MySQL high availability cluster deployment and failover implementation

Table of contents 1. MHA 1. Concept 2. Compositio...

JavaScript custom plug-in to implement tab switching function

This article shares the specific code of JavaScri...

The forgotten button tag

Note: This article has been translated by someone ...

How to install tomcat8 in docker

1. Install tomcat8 with docker 1. Find the tomcat...

How to make a tar file of wsl through Docker

I've been playing with the remote development...

Vue uses GraphVis to develop an infinitely expanded relationship graph

1. Go to the GraphVis official website to downloa...

HTML multimedia application: inserting flash animation and music into web pages

1. Application of multimedia in HTML_falsh animat...

Detailed explanation of the process of building and running Docker containers

Simply pull the image, create a container and run...