search
HomeOperation and MaintenanceNginxHow to configure nginx ssl certificate to achieve https access

一,环境说明

服务器系统:ubuntu16.04lts

服务器ip地址:47.89.12.99

域名:bjubi.com

二,域名解析到服务器

在阿里云控制台-产品与服务-云解析dns-找到需要解析的域名点“解析”,进入解析页面后选择【添加解析】按钮会弹出如下页面:

主机记录这里选择@,记录值就是服务器ip地址,确认。

How to configure nginx ssl certificate to achieve https access

三,申请ca证书

在阿里云控制台-产品与服务-安全(云盾)-ca证书服务(数据安全),点击购买证书,

How to configure nginx ssl certificate to achieve https access

选择“免费版dv ssl”,点击立即购买:

How to configure nginx ssl certificate to achieve https access

然后点去支付:

How to configure nginx ssl certificate to achieve https access

最后确认支付:

How to configure nginx ssl certificate to achieve https access

就会回到管理界面:

How to configure nginx ssl certificate to achieve https access

点击“补全”,输入要解析的域名,点下一步:

说明:因为我们这里申请的是开发版免费证书,所以一个证书仅支持一个域名认证,不支持通配符。

How to configure nginx ssl certificate to achieve https access

等待几分钟,证书状态变为“已签发”后,证书就申请成功了。

四,下载证书

列表中找到已签发的证书,下载:

How to configure nginx ssl certificate to achieve https access

进入下载页面,找到ngin页签中nginx配置信息,并“下载证书 for nginx”:

How to configure nginx ssl certificate to achieve https access

记录以下内容,为了一会儿配置nginx用:

How to configure nginx ssl certificate to achieve https access

下载的文件有两个:

1,214292799730473.pem

2,214292799730473.key

五,服务器安装,配置nginx

登录到服务器:

$ apt-get update // 更新软件
$ apt-get install nginx // 安装nginx

1,nginx的安装目录为:/etc/nginx/。进入目录,增加cert/文件夹,把刚刚下载的两个文件上传到cert/文件夹中。

2,在/etc/nginx/sites-enabled/下,增加bjubi.com文件。内容如下:

说明:下面的配置是对443端口和80端口进行监听,443端口要启用ssl。监听443端口的server配置可以仿照上面ca认证页面的nginx配置示例进行配置。

root节点笔者创建了一个bjubi.com/的文件夹,专门存放来自这个域名的请求以示区分。

bjubi.com/文件夹下增加一个index.html文件,里面仅仅写了一行

welcome。
server {
  listen 443;
  server_name bjubi.com; // 你的域名
  ssl on;
  root /var/www/bjubi.com; // 前台文件存放文件夹,可改成别的
  index index.html index.htm;// 上面配置的文件夹里面的index.html
  ssl_certificate cert/214292799730473.pem;// 改成你的证书的名字
  ssl_certificate_key cert/214292799730473.key;// 你的证书的名字
  ssl_session_timeout 5m;
  ssl_ciphers ecdhe-rsa-aes128-gcm-sha256:ecdhe:ecdh:aes:high:!null:!anull:!md5:!adh:!rc4;
  ssl_protocols tlsv1 tlsv1.1 tlsv1.2;
  ssl_prefer_server_ciphers on;
  location / {
    index index.html index.htm;
  }
}
server {
  listen 80;
  server_name bjubi.com;// 你的域名
  rewrite ^(.*)$ https://$host$1 permanent;// 把http的域名请求转成https
}

配置完成后,检查一下nginx配置文件是否可用,有successful表示可用。

$ nginx -t // 检查nginx配置文件

配置正确后,重新加载配置文件使配置生效:

$ nginx -s reload // 使配置生效

至此,nginx的https访问就完成了,并且通过rewrite方式把所有http请求也转成了https请求,更加安全。

如需重启nginx,用以下命令:

$ service nginx stop // 停止
$ service nginx start // 启动
$ service nginx restart // 重启

七,访问效果

输入http:bjubi.com也会自动跳转至https页面。

说明:如果是云服务器比如阿里云ecs,需要到阿里云ecs的管理后台的安全组,修改端口过滤规则把80端口和443端口开放才能访问到。

How to configure nginx ssl certificate to achieve https access

The above is the detailed content of How to configure nginx ssl certificate to achieve https access. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure nginx in WindowsHow to configure nginx in WindowsApr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment