Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure ssl Certificate in nginx

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to configure ssl certificate in nginx, for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

First, apply for ssl certificate

I use the free ssl certificate of Tencent halo. After the application is successful, you can download the certificate. This is the file I downloaded and unzipped, and then put it.

Second, upload the ssl certificate and configure it

Select the two files in the nginx folder, and then upload them to the nginx directory through xftp software or other means. I chose the directory of the conf file.

After getting it done, start to configure the contents of conf. Here is my configuration. I used the 1.18 version of nginx. It is said that the old version is a little different. Here is a reference link to https://cloud.tencent.com/document/product/400/35244.

# user nobody;worker_processes 1 the errorless log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream # log_format main'$remote_addr-$remote_user [$time_local] "$request" #'$status $body_bytes_sent "$http_referer" #'"$http_user_agent"$http_x_forwarded_for"; # access_log logs/access.log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65 # gzip on; server {listen 443 default_server ssl; server_name www.tiantianboke.com; ssl_certificate 1 default_server ssl www.tiantianboke.com; ssl_certificate_key 2 www.tiantianboke.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m # prohibit server version from appearing in header to prevent hackers from exploiting version vulnerabilities to attack server_tokens off; # charset koi8-r; # access_log logs/host.access.log main; location / {root html; index index.html index.htm } location / api {proxy_pass http://127.0.0.1:5000;}

Third, check the nginx configuration file

After the configuration and saving, use the nginx-t command to check that the configuration content is normal, if the

Nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in / usr/local/nginx/conf/nginx.conf:xxx

At this time, you need to configure it. First stop nginx running.

And then

Find name configure

Find all configure in the directory

Then go to the nginx-1.18.0 directory and execute

. / configure-- prefix=/usr/local/nginx-- with-http_ssl_module / / plus ssl support for http module

And then execute

Make

Build, do not execute make install

And then

Cp objs/nginx / usr/local/nginx/sbin overwrites the previous binaries.

When the above operations are completed, execute nginx-t and you will see that there is no problem with the configuration file

Then restart nginx and browse the website

(if the page of the website you visit has a http request, then the url address bar will indicate that it is not secure, and you need to find a way to change his http address to https.)

But after I finished the configuration, I found that there was a problem with my page. There was a cross-domain problem with the signalr (server pushing messages to the client) js, and then my Baidu solution was

Configure the content

Location / chatHub {proxy_pass http://127.0.0.1:5000; proxy_http_version 1.1; # without this sentence, there will be a 409 error proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" } this is the answer to the question about how to configure the ssl certificate in nginx. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report