Linux Nginx Https搭建

Nginx Https搭建环境:

1、生成证书

[[email protected] CA]# openssl  genrsa -des3 -out jroa.key 1024        \\创建一个RSA秘钥
Generating RSA private key, 1024 bit long modulus
...............++++++
..................................++++++
e is 65537 (0x10001)
Enter pass phrase for jroa.key:            \\提示输入密码
Verifying - Enter pass phrase for jroa.key:        \\再次输入
[[email protected] CA]# openssl rsa -in jroa.key -out jroa_nopass.key            \\生成一个不不要输入密码的密码
Enter pass phrase for jroa.key:        \\输入之前的密码
writing RSA key        \\生成RSA成功  
[[email protected] CA]# openssl req -new -key jroa_nopass.key -out jroa.csr        \\生成一个需要待签的证书
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN            \\提示输入国家代码
State or Province Name (full name) []:FJ        \\省份
Locality Name (eg, city) [Default City]:XM        \\市区
Organization Name (eg, company) [Default Company Ltd]:jroa    \\公司名字
Organizational Unit Name (eg, section) []:Tech        \\部门
Common Name (eg, your name or your server‘s hostname) []:www.jroa.com    \\这个最重要,就是我们网站的主机名
Email Address []:[email protected]    \\邮件

Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:        \\直接按回车
An optional company name []:        \\直接按回车
[[email protected] CA]# openssl x509 -req -days 365 -in jroa.csr -signkey jroa.key -out jroa.crt \\签署证书
Signature ok
subject=/C=CN/ST=FJ/L=XM/O=jroa/OU=Tech/CN=www.jroa.com/[email protected]
Getting Private key
Enter pass phrase for jroa.key:        \\输入之前创建RSA秘钥的密码

2、Nginx开启--with-http_ssl_module

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[[email protected] vhost]#

3、配置Nginx:

[[email protected] conf]# cat nginx.conf
user  www www;

#user  nobody;
worker_processes  1;
pid        logs/nginx.pid;
error_log  logs/error.log  notice;

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;

include /usr/local/nginx/conf/vhost/*.conf;        \\一般我们都是在vhost下定义Server
}
[[email protected] conf]# cd vhost/
[[email protected] vhost]# cat www.jroa.com.conf
server {
        listen       80;
        server_name  www.jroa.com;
        access_log /data/site/www.jroa.com/www.jroa.com.access.log;
        index index.php index.html index.html;
        root /data/site/www.jroa.com;

        location ~ .*\.(php)?$ {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        }
	location / {
             index index.html index.htm index.php;
        if ( !-e $request_filename){
             rewrite ^/(.*)$ /index.php?s=$1 last;
             break;
                   }
                }
}
server {
    listen 443;
    server_name  www.jroa.com;
    access_log /data/site/www.jroa.com/www.jroa.com1.access.log;
    index index.php index.html index.html;
    root /data/site/www.jroa.com;
    if ($host != ‘www.jroa.com‘ )
      {
    	 rewrite ^/(.*)$ http://www.jroa.com/$1 permanent;
      }
        ssl                  on;
        ssl_certificate      ssl/jroa.crt;             \\在conf建一个ssl目录
        ssl_certificate_key   ssl/jroa.key;            \\在conf建一个ssl目录,如果换成jroa_nopass.key则启动就不需要输入密码
        ssl_session_timeout  5m;
        ssl_protocols  SSLv3 TLSv1;
        #ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
	ssl_ciphers HIGH:!aNULL:!MD5:!EXPORT56:!EXP;
        ssl_prefer_server_ciphers   on;
     location ~ .*\.(php)?$ {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        }
     location / {
        index index.html index.htm index.php;
        if ( !-e $request_filename){
        rewrite ^/(.*)$ /index.php?s=$1 last;
        break;
                }
        }
}

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -t
Enter PEM pass phrase:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] vhost]# /usr/local/nginx/sbin/nginx
Enter PEM pass phrase:
[[email protected] vhost]# netstat -tunlp| grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      8837/nginx          
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      8837/nginx

我们访问下:自签证书浏览器是不会认识的,有些还会提示风险!注意设置浏览器不然访问不了的。

时间: 2024-08-07 12:22:43

Linux Nginx Https搭建的相关文章

linux+nginx+php搭建学习笔记

文章内内容均参考网络上各类文章后自行整理,感谢原文作者的分享. OS环境CentOS release 6.6 一,安装配置nginx 下载目前nginx最新的稳定版本nginx-1.8.0 # wget http://nginx.org/download/nginx-1.8.0.tar.gz 解压编译安装 # tar -xvf nginx-1.8.0.tar.gz# cd nginx-1.8.0# ./configure --prefix=/usr/local/nginx --with-http

如何搭建LNMP环境(Linux+Nginx+MySql+Php)来运行wordpress

一.前言 今天是周六,积累了很多天的内容都要在今天来释放了,因为最近想弄一个自己的主页,查看网上之后,都说wordpress很不错,他是一个开源的后台程序,可以用来搭建自己的博客,论坛等功能.但是有一个蛋疼的地方,他是php写的,之前只弄过JavaWeb相关的后台程序,php不太熟呢,以前也是搭建过Linux+Apache+Tomcat+JavaWeb+MySql,那么这次也正好是一个机会学习一下如何搭建后台PHP系统,这里也是网上比较流行的后台系统组合:Linux+Nginx+MySql+Ph

LNMP环境搭建(linux+Nginx + Mysql + PHP)

linux+Nginx + Mysql + PHP 搭配可以说目前使用比较广泛那要想在这台刚安装好系统的服务器上配置这环境,有多种方式 一.傻瓜式一键安装 为了让大家安装环境能简单,方便.有人把它们集成了一个包. 1.LNMP一键安装包网址:lnmp.org,里面介绍一些要求,功能等进入到安装页面说明,找到相关的安装说明,运行,然后一步一步按照操作就行了,比较简单 2.使用宝塔,这是更加傻瓜,方便的一款工具,操作服务,只需在网站后台,点点鼠标,就能完成网址:bt.cn找到,linux安装,里面有

Linux下PHP+Nginx环境搭建

PHP+Nginx环境搭建 作者:王宇阳( Mirror )^_^ 参考文章: ? Nginx+PHP+MySQL安装参考 ? PHP源码安装经验 ? PHP源码环境搭建过程中常见问题 CentOS环境 配置CentOS-7网络: CentOS(最小安装)默认是不打开网络的 启动网络 vi打开:/etc/sysconfig/network-scripts/ifcfg-ens33 文件 将 "ONBOOT:no"属性修改为:"ONBOOT:yes" 重启网络服务 #

详述Linux系统中搭建Nginx动静分离

Nginx动静分离介绍 Nginx的静态处理能力很强,但是动态处理能力不足,因此,在企业中常用动静分离技术 针对PHP的动静分离 静态页面交给Nginx处理 动态页面交给PHP-FPM模块或Apache处理 在Nginx的配置中,是通过location配置段配合正则匹配实现静态与动态页面的不同处理方式 反向代理原理 Nginx不仅能作为Web服务器,还具有反向代理.负载均衡和缓存的功能 Nginx通过proxy模块实现将客户端的请求代理至上游服务器,此时nginx与. 上游服务器的连接是通过ht

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档

nginx 环境搭建(基于linux)

Nginx是一种服务器软件,故而其最主要.最基本的功能当然是可以与服务器硬件结合,让程序员可以将程序放在Nginx服务器上,将程序发布出去,让成千上万的网民可以浏览.除此之外,Nginx是一种高性能的HTTP和反向代理服务器,同时也是一个代理邮件服务器.也就是说,我们Nginx上可以发布网站,也可以实现负载均衡的功能,还可以作为邮件服务器实现收发邮件等功能.所谓的负载均衡是指,当同时有N多用户访问我们服务器的时候,为了减少服务器压力,我们需要将用户分别引入各服务器,分担服务器的压力. 首先说II

为苹果ATS和微信小程序搭建 Nginx + HTTPS 服务

昨天测试开发微信小程序,才发现微信也要求用HTTPS加密数据,想来是由于之前苹果的ATS审核政策的缘故吧,微信想在苹果上开放小程序必然也只能要求开发者必须使用HTTPS了,于是在服务器上测试安装Nginx+HTTPS服务. 安装 HTTPS 最麻烦的问题应该就是获取证书了,证书感觉种类也挺复杂的,有好几种,单域.泛域.多域...还有个种标准乱七八糟的感觉,而且收费很高,还是每年买的. 现在各个云服务商也都有提供各种基础功能的免费证书,但似乎很多只对单域免费,这里的单域是指每个二级域名都算是一个域

让你的网站走https(linux, nginx)

自己编写 适合像我这样新手(我也是刚快要弄明白) 服务器已经通过阿里云web一键安装包安装完成 环境是linux+nginx 已经申请域名 购买免费CA证书 购买 验证 成功 下载上传证书 下载证书 上传证书 修改证书权限 nginx配置 nginx虚拟机配置 http强制走https 小坑 购买免费CA证书 我们可以在阿里云购买免费的证书 有效期一年 只能一个域名 可以购买多个免费的 购买 购买 进入之后就直接购买就行了 支付成功 验证 购买成功之后可以回到控制台,找到信息补全按钮,进行补全信