Nginx1.8.1 编译扩展https
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的更多相关文章
- centos6.5中 nginx-1.6.3 编译安装
参考来源:http://nginx.org/en/docs/configure.html nginx-1.6.3 编译安装:1) ./configure --help 查看编译选项 2) 需要安装一下 ...
- 继《在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib》修订
在之前的<在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib>中有些问题,后来由于时间不是很充足,故现在对其中的问题进行完善,如下所示对红色框框中的相应的 ...
- nginx之 nginx-1.9.7 编译安装、理论简介
nginx是一个web网站常用的高性能http和反向代理服务器,其具有较好的并发能力,被网易.百度.腾讯.新浪等网站广泛使用. 一. 理论简介 1.首先弄清楚正向代理和反向代理 正向代理:代理客户端, ...
- nginx-1.12.2编译安装指导
nginx-1.12.2编译安装 下载源码包 安装 安装后配置 下载源码包 下载地址:http://nginx.org/en/download.html nginx-1.12.2:http://ngi ...
- 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 ...
- nginx-1.10.3 编译安装
1.系统环境 [root@crazy-acong ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@crazy-acong ~] ...
- (一)在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 及一些问题
一.准备工作: 1.下载OpenCV安装包:https://github.com/opencv/opencv 安装过程实际上就是解压过程,安装完成后得到(这里修改了文件名): 2.下载opencv_c ...
- 在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib
为什么要CMake,这里我陈述自己的想法,作为一个刚使用opencv库的小白来说,有以下大概三点内容 1.由于在学习图像处理滤波器中,需要用到各种边缘保护滤波器(EPS)算法,但是这些算法在OpenC ...
- windows下编译支持https的libcurl
本文参考http://blog.csdn.net/fragmentalice/article/details/39430293特此感谢.公司项目中用到几个http get请求,用的libcurl开源库 ...
随机推荐
- jQuery高度及位置操作
1. 获取滑轮位置,scrolltop:上下滚动的意思. <!DOCTYPE html> <html lang="en"> <head> < ...
- 2个 List<T>进行数据合并
var userF = new List<User>(); User m1 = new User() { Id = "0" }; userF.Add(m1); var ...
- [NOI2011]兔兔与蛋蛋游戏 二分图博弈
题面 题面 题解 通过观察,我们可以发现如下性质: 可以看做是2个人在不断移动空格,只是2个人能移动的边不同 一个位置不会被重复经过 : 根据题目要求,因为是按黑白轮流走,所以不可能重复经过一个点,不 ...
- [POI2012]OKR-A Horrible Poem hash
题面:洛谷 题解: 首先我们需要知道一个性质,串s的最小循环节 = len - next[len].其中next[len]表示串s的一个最长长度使得s[1] ~ s[next[len]] == s[l ...
- Mybatis笔记四:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String'
错误异常:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for pr ...
- hadoop(三)HDFS基础使用
一.HDFS前言 1. 设计思想 分而治之:将大文件,大批量文件,分布式的存放于大量服务器上.以便于采取分而治之的方式对海量数据进行运算分析 2. 在大数据系统架构中的应用 ...
- scala(三)
一.面向对象编程——类 1.定义一个简单的类 class HelloWorld { private var name = "leo" def sayHello() { print( ...
- java发送邮件功能[转]
原文链接:https://blog.csdn.net/jjkang_/article/details/56521959 Javamail遵循两个协议,一个是smtp协议,另一个是pop3协议.一般情况 ...
- Oracle把本地的dmp备份文件导入到本地的Oracle数据库中语句
----------------------------------------------------------------------------- 导入语法 imp usename/passw ...
- Arrays.asList方法遇到的问题
在使用Arrays.asList(T...a)方法时,遇到了 java.lang.UnsupportedOperationException 异常. 后来发现,该方法返回的类型是Arrays$Arr ...