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. castle activerecord 学习过程出现的问题

    优点: 1.CRUD:代码简洁 2.不用配置map 3.自带事务方便 4.自带IOC 5.自带 数据有效性验证 缺点: 1.自增长(Oracle 一直提示序号不存在,有空继续尝试) 2.多条件,直接用 ...

  2. Redis学习笔记一:Redis安装

    Redis安装 1.下载进入redis官网下载redis-xxx.tar.gz包 2.将redis-xxx.tar.gz拷贝到Linux某一目录下并对其进行解压 tar -zxvf Redis-xxx ...

  3. 【CF666E】Forensic Examination(后缀自动机,线段树合并)

    [CF666E]Forensic Examination(后缀自动机,线段树合并) 题面 洛谷 CF 翻译: 给定一个串\(S\)和若干个串\(T_i\) 每次询问\(S[pl..pr]\)在\(T_ ...

  4. SID(安全标识符)

    creating a SID for the Everyone group. DWORD SidSize; PSID TheSID; LPTSTR p; SidSize = SECURITY_MAX_ ...

  5. Java考试题

    1.     public class GC { 2.     private Object o; 3.     private voiddoSomethingElse(Object obj) { o ...

  6. bzoj4144【AMPPZ2014】Petrol

    题解:  首先注意到起点和终点都是加油站;          假设中途经过某个非加油站的点u,u连到v,离u最近的加油站是x,那么从u到x加油后回到u,再到v一定不比直接从u到v差:        因 ...

  7. shell中的引用

    By francis_hao    Mar 31,2018   引用,用来移除某个字符或单词对于shell的特殊含义 每个元字符对于shell都有特殊含义,可分割单词,如果想使用其本身的含义就需要用到 ...

  8. CSUST 四月选拔赛个人题解

    这场比赛演的逼真,感谢队友不杀之恩 总结:卡题了赶紧换,手上捏着的题尽快上机解决 http://csustacm.com:4803/ 1113~1122 1113:六学家 题意:找出满足ai+aj=a ...

  9. Jenkins基于角色的项目权限管理

    参考博客:http://www.cnblogs.com/davidwang456/p/3701972.html 一.简介 由于jenkins默认的权限管理体系不支持用户组或角色的配置,因此需要安装第三 ...

  10. 在使用Hibernate save()方法的时候 报错: org.hibernate.exception.ConstraintViolationException:could not perform addBath

    org.hibernate.exception.ConstraintViolationException:could not perform addBath 错误可能原因:实体属性的值与数据库字段类型 ...