nginx无缝编译扩展https

本贴只限用于通过编译安装的nginx,如果用的是yum源安装请卸载后参见 http://www.cnblogs.com/rslai/p/7851220.html 安装nginx部分。

一、重新编译nginx

1、查看nginx是否支持ssl

/usr/local/nginx/sbin/nginx -V

  如果显示“--with-http_ssl_module”则表示https模块已安装。

  

2、 如果没有则需要重新编译。找到之前安装 Nginx 时的编译目录,配置ssl模块

  之前安装目录在 /usr/local/src/nginx-1.8.1 ,如果你的在不同目录请坐适当修改。

cd /usr/local/src/nginx-1.8.1
./configure --with-http_ssl_module
make

3、编译好后通过复制到方式升级,不要执行 make install 安装

# 备份原有的 nginx
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
# 把新编译的nginx拷贝到相应的目录下
cp /usr/local/src/nginx-1.8.1/objs/nginx /usr/local/nginx/sbin/

4、最后进行平滑升级

cd /usr/local/src/nginx-1.8.1
make upgrade

5、再次查看nginx是否支持ssl

/usr/local/nginx/sbin/nginx -V  

二、生成私有(不受浏览器信任)的SSL证书,如果你有公有证书请跳过此步

1、生成一个RSA密钥(xh),记住你输入的密码

openssl genrsa -des3 -out xh.key 1024

  

2、拷贝一个不需要输入密码的密钥文件

openssl rsa -in xh.key -out xh_nopass.key

 

3、生成一个证书请求

openssl req -new -key xh.key -out xh.csr

4、自己签发证书

openssl x509 -req -days 365 -in xh.csr -signkey xh.key -out xh.crt

5、复制crt和key到指定目录

  注:key文件一定要复制刚才生成的 nopass 的key,复制到的目录也可以需要修改

cp xh.crt /etc/ssl/
cp xh_nopass.key /etc/ssl/

三、修改 nginx.conf 配置文件

到此为止升级完成,如果想启用https还需要修改 nginx.conf 文件

1、打开 nginx.conf 配置文件

cd /usr/local/nginx/conf
vim nginx.conf

2、修改配置文件如下,注意 root目录,配置文件中 php代码放在了 /home/www,请根据实际情况修改

  此配置文件配置了将80端口访问自动转到443端口。

#user  www www;
worker_processes 1;
#pid /var/run/nginx.pid;
events {
worker_connections 51200;
}
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"';
sendfile on;
keepalive_timeout 300;
client_max_body_size 20m;
#include /etc/nginx/conf.d/*.conf;
server
{
#listen [::]:80;
listen 80;
server_name 192.168.3.219;
return 301 https://$server_name$request_uri;
index index.html index.htm index.php;
root /home/www/public;
if (!-e $request_filename)
{
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location /nginx_status
{
#stub_status on;
#access_log /mydata/nginx.log;
auth_basic "NginxStatus";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 24h;
root /home/www/public;
}
location ~ /\.
{
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
server
{
#listen [::]:443 ssl;
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl/xh.crt;
ssl_certificate_key /etc/ssl/xh_nopass.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:-LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
server_name 192.168.3.219;
index index.html index.htm index.php;
root /home/www/public;
if (!-e $request_filename)
{
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location /nginx_status
{
#stub_status on;
#access_log /home/www/nginx.log;
auth_basic "NginxStatus";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 24h;
root /home/www/public;
}
location ~ /\.
{
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
#fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}

3、不停止nginx服务重读配置文件

/usr/local/nginx/sbin/nginx   -s  reload

参考文献:

  http://blog.csdn.net/dreamsqifan/article/details/73467672

  http://www.linuxidc.com/Linux/2013-08/88271.htm

Nginx1.8.1 编译扩展https的更多相关文章

  1. centos6.5中 nginx-1.6.3 编译安装

    参考来源:http://nginx.org/en/docs/configure.html nginx-1.6.3 编译安装:1) ./configure --help 查看编译选项 2) 需要安装一下 ...

  2. 继《在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib》修订

    在之前的<在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib>中有些问题,后来由于时间不是很充足,故现在对其中的问题进行完善,如下所示对红色框框中的相应的 ...

  3. nginx之 nginx-1.9.7 编译安装、理论简介

    nginx是一个web网站常用的高性能http和反向代理服务器,其具有较好的并发能力,被网易.百度.腾讯.新浪等网站广泛使用. 一. 理论简介 1.首先弄清楚正向代理和反向代理 正向代理:代理客户端, ...

  4. nginx-1.12.2编译安装指导

    nginx-1.12.2编译安装 下载源码包 安装 安装后配置 下载源码包 下载地址:http://nginx.org/en/download.html nginx-1.12.2:http://ngi ...

  5. scala学习(idea编译过程https://blog.csdn.net/guiying712/article/details/68947747)

    scala官网 https://www.scala-lang.org/ 菜鸟教程学习 http://www.runoob.com/scala/scala-basic-syntax.html w3sch ...

  6. nginx-1.10.3 编译安装

    1.系统环境 [root@crazy-acong ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@crazy-acong ~] ...

  7. (一)在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 及一些问题

    一.准备工作: 1.下载OpenCV安装包:https://github.com/opencv/opencv 安装过程实际上就是解压过程,安装完成后得到(这里修改了文件名): 2.下载opencv_c ...

  8. 在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib

    为什么要CMake,这里我陈述自己的想法,作为一个刚使用opencv库的小白来说,有以下大概三点内容 1.由于在学习图像处理滤波器中,需要用到各种边缘保护滤波器(EPS)算法,但是这些算法在OpenC ...

  9. windows下编译支持https的libcurl

    本文参考http://blog.csdn.net/fragmentalice/article/details/39430293特此感谢.公司项目中用到几个http get请求,用的libcurl开源库 ...

随机推荐

  1. 【刷题】BZOJ 4566 [Haoi2016]找相同字符

    Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两个子串中有一个位置不同. Input 两行,两个字符串s1,s2,长度分别为 ...

  2. 分治FFT

    目录 分治FFT 目的 算法 代码 分治FFT 目的 解决这样一类式子: \[f[n] = \sum_{i = 0}^{n - 1}f[i]g[n - i]\] 算法 看上去跟普通卷积式子挺像的,但是 ...

  3. 洛谷 P4503 [CTSC2014]企鹅QQ 解题报告

    P4503 [CTSC2014]企鹅QQ 题目背景 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即 ...

  4. 应用程序的日志通过rsyslog推送到syslog服务器

    centos5系列系统自带为syslog1.4.1 centos6系列自带rsyslog版本为5.8.10 centos7系列自带rsyslog版本为7.4.7 目前最新版rsyslog为8.27.0 ...

  5. 日志分割工具——cronolog

    使用cronolog可以格式化日志文件的格式,比如按时间分割,易于管理和分析. 1.下载软件 http://cronolog.org/download/index.html 用法见 lighttpd配 ...

  6. 实现了一下Berlekamp-Massey

    //from https://www.cnblogs.com/TSHugh/p/9265155.html //在FP中求固定项数数列的线性递推式 //此递推式严格符合数学定义,故可能在末尾出现一些看起 ...

  7. oracle 数据库记录

    /*----------------------------------------------------------------------------*/ 问题1[--------] Selec ...

  8. navicat for mysql 导出数据的坑

    navicat 选择转储结构和数据的时候,生成的 sql 文件会比较大,因为每一条数据都会生成一条 sql 语句,所以会导致 使用 source 还原的时候会很慢很慢很慢, 而使用 mysqldump ...

  9. Libevent学习笔记(四) bufferevent 的 concepts and basics

    Bufferevents and evbuffers Every bufferevent has an input buffer and an output buffer. These are of ...

  10. jni 找不到本地方法的实现

    使用JNI开发,需要在java端声明本地方法,并在jni层实现本地方法. 有时运行项目时会先抛出异常:No implementation found for native xxx 然后直接挂掉:jav ...