概要
本文以阿里云为例,浅要介绍如何将域名指向你的服务器,以及如何配置ssl和非ssl的方式。
购买域名
购买域名不做描述,本文域名以helloword.com
为例
域名实名与备案
购买后,不实名和备案是无法使用的,这里不展开赘述
配置域名解析
域名解析就是将你的域名指向你的服务器:访问域名+ip=访问你的服务器+ip
注意:主机记录可以在你的域名前拼接指定的域名前缀,比如hello.helloword.com
在阿里云控制台依次点击:域名控制台
->域名列表
->操作:域名解析
,如下图:
配置nginx(http)
首先不使用ssl证书,进行一个简要的配置,此模式不支持使用https进行访问:
登录服务器,配置nginx.conf
文件吗,在server块进行如下配置:
server { listen 80; server_name hello.helloword.com; root html; index index.html index.htm; location / { proxy_http_version 1.1; proxy_set_header connection ""; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
注意:监听的端口,也可配置成除443以外的其他端口,并且可重复配置,因为是通过域名访问的。
访问地址:端口如果是80则可省略:hello.helloword.com
配置nginx(ssl+https)
https需要使用ssl证书,首先申请一个ssl证书
申请并配置ssl证书
数字证书管理服务
->ssl证书
->免费证书->创建证书(如果没有免费额度先购买下,免费的)
->证书申请
,如下图:
然后点击下一步,dns验证,然后提交审核即可,耐心等待通过后进行下一步
下载ssl证书
审核通过后,在ssl主页面点击下载,解压后得到两个证书文件,将这两个文件放到服务器上,接下来进行nginx的配置
配置nginx
登录服务器,配置nginx.conf
文件吗,在server块进行如下配置:
server { listen 80; listen 443 ssl; server_name hello.helloword.com; root html; index index.html index.htm; ssl_certificate /etc/nginx/cert/helloword/hello.helloword.com.pem; ssl_certificate_key /etc/nginx/cert/helloword/hello.helloword.com.key; ssl_ciphers ecdhe-rsa-aes128-gcm-sha256:ecdhe:ecdh:aes:high:!null:!anull:!md5:!adh:!rc4; ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_session_timeout 5m; ssl_prefer_server_ciphers on; location / { proxy_http_version 1.1; proxy_set_header connection ""; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
访问地址:https://hello.helloword.com
到此这篇关于nginx配置域名(ssl和非ssl形式)的实现示例的文章就介绍到这了,更多相关nginx配置ssl和非ssl域名内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论