Linux 搭建Nginx并添加配置 SSL 证书
[root@nginx ~]# yum -y install gcc-c++
[root@nginx ~]# yum -y install pcre pcre-devel
[root@nginx ~]# yum -y install zlib zlib-devel
[root@nginx ~]# yum -y install openssl openssl-devel
[root@nginx ~]# wget -c https://nginx.org/download/nginx-1.10.3.tar.gz
[root@nginx ~]# yum -y install wget
[root@nginx ~]# tar -zxvf nginx-1.10.3.tar.gz
[root@nginx include]# groupadd nginx
[root@nginx include]# useradd -g nginx -d /home/nginx nginx
[root@nginx include]# passwd nginx
Sticky是nginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识名为route
.客户端首次发起访问请求,nginx接收后,发现请求头没有cookie,则以轮询方式将请求分发给后端服务器。
.后端服务器处理完请求,将响应数据返回给nginx。
.此时nginx生成带route的cookie,返回给客户端。route的值与后端服务器对应,可能是明文,也可能是md5、sha1等Hash值
.客户端接收请求,并保存带route的cookie。
.当客户端下一次发送请求时,会带上route,nginx根据接收到的cookie中的route值,转发给对应的后端服务器。 http {
#OK include vhost/xxx.conf;
upstream shop_server{
sticky;
#Sticky是nginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上
# server 192.168.1.23;
server 192.168.1.24;
# server 192.168.1.25;
keepalive 32;
}
[root@nginx ~]# tar -zxvf nginx-goodies-nginx-sticky-module-ng-08a395c66e42..gz
[root@nginx ~]# mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-1.2.
查找并删除mysql有关的文件
find / -name nginx
rm -rf
上边查找到的路径,多个路径用空格隔开,或者下边一条命令即可
find / -name nginx|xargs rm -rf
[root@nginx ~]# cd nginx-1.10.
[root@nginx nginx-1.10.]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --add-module=/usr/local/nginx-sticky-1.2.
./configure \
--user=nginx --group=nginx \ #安装的用户组
--prefix=/usr/local/nginx \ #指定安装路径
--with-http_stub_status_module \ #监控nginx状态,需在nginx.conf配置
--with-http_ssl_module \ #支持HTTPS
--with-http_sub_module \ #支持URL重定向
--with-http_gzip_static_module #静态压缩
--add-module=/usr/local/nginx-sticky-1.2. #安装sticky模块
[root@nginx nginx-1.10.]# make && make install

[root@nginx nginx-1.10.3]# sed -i '12a #include <openssl/sha.h>' /usr/local/nginx-sticky-1.2.5/ngx_http_sticky_misc.c
[root@nginx nginx-1.10.3]# sed -i '12a #include <openssl/md5.h>' /usr/local/nginx-sticky-1.2.5/ngx_http_sticky_misc.c
[root@nginx nginx-1.10.3]# make && make install
[root@nginx bin]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
[root@nginx ~]# nginx -v
nginx version: nginx/1.10.3
[root@nginx ~]# nginx -V
nginx version: nginx/1.10.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
configure arguments: --add-module=/root/nginx-sticky-1.2.5/
[root@nginx nginx-1.10.3]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@nginx nginx-1.12.2]# nginx -s stop
[root@nginx nginx-1.12.2]# nginx -s quit
[root@nginx nginx-1.12.2]# nginx -s reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
[root@nginx rc.d]# cd /etc/rc.d
[root@nginx rc.d]# sed -i '13a /usr/local/nginx/sbin/nginx' /etc/rc.d/rc.local
[root@nginx rc.d]# chmod u+x rc.local
[root@nginx ~]# view /usr/local/nginx/conf/nginx.conf
[root@nginx ~]# nginx -s reload
[root@nginx ~]# firewall-cmd --state
running
[root@nginx ~]# systemctl stop firewalld.service
[root@nginx ~]# firewall-cmd --state
not running

7.开始配置SSL证书(证书需另行获取,获取的途径很多,如阿里云的服务或第三方服务购买)
server {
listen 80;
server_name 需要访问的域名; rewrite ^(.*) https://$server_name$1 permanent; #这句是代表 把 http的域名请求转成https #charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://需要访问的域名; #因为这里还是80端口,所以保持http就可以了 }
}
# HTTPS server
#
server {
listen 443 ssl;
server_name 需要访问的域名,这里也不用加https; ssl on; ssl_certificate /usr/local/nginx/ssl/ssl.pem; #这里是ssl key文件存放的绝对路径,根据自己的文件名称和路径来写
ssl_certificate_key /usr/local/nginx/ssl/ssl.key; #这里是ssl key文件存放的绝对路径,根据自己的文件名称和路径来写 ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
proxy_pass http://需要访问的域名:8080/;
}
}
[root@localhost sbin]# nginx -t

#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; 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; #gzip on; server {
listen 80;
server_name test.feihe.com;
#rewrite ^(.*) https://$server_name$1 permanent; #这句是代表 把http的域名请求转成https #charset koi8-r; #access_log logs/host.access.log main; location / {
root html/;
index index.html index.htm;
} location /coa/ {
proxy_pass http://localhost:8080;
} location /front/ {
proxy_pass http://localhost:8080;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server ssl_protocols SSLv2 SSLv3 TLSv1; server {
listen 443 ssl;
server_name test.feihe.com; ssl on;
ssl_certificate /usr/local/nginx/ssl/_.xx.com_bundle.crt; #这里是ssl pem文件存放的绝对路径
ssl_certificate_key /usr/local/nginx/ssl/_.xx.com.key; #这里是ssl key文件存放的绝对路径 ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on; location / {
root html/;
index index.html index.htm;
} location /coa/ {
proxy_pass http://localhost:8080;
} location /front/ {
proxy_pass http://localhost:8080;
}
} }
Linux 搭建Nginx并添加配置 SSL 证书的更多相关文章
- nginx下如何配置 ssl证书?腾讯云ssl证书为例!
nginx下如何配置 ssl证书?腾讯云ssl证书为例! 目前为止,https已经成为一种趋势,想要开启https就需要ssl证书. 首先,为域名注册ssl证书. 腾讯云注册地址:https://cl ...
- 网站是HTTP?10分钟变成HTTPS!域名免费添加配置SSL证书,变成https//环境
对于小程序request请求需要https域名.navigator.geolocation定位也需要在https环境下才可以生效等问题: 前端开发越来越需要https环境来来测试一下API接口和各类问 ...
- nginx安全:配置ssl证书(https证书)
一,配置https证书的意义 https协议是由SSL+http协议构建的安全协议,支持加密传输和身份认证, 安全性比http要更好,因为数据的加密传输,更能保证数据的安全性和完整性 例如:不使用ht ...
- Linux中Nginx中添加自签证书TLS
创建自签证书TLS openssl req \ -newkey rsa: \ -x509 \ -nodes \ -keyout test.com.key \ -new \ -out test.com. ...
- 阿里云配置ssl证书
一.申请证书和下载证书(阿里云申请) 二.在nginx服务器上配置ssl证书 1.检查服务器是否安装openssl 2.在nginx conf 文件夹创建 cret 文件,放置证书 [root@web ...
- linux nginx 配置ssl证书访问
http://www.linuxidc.com/Linux/2013-08/88271.htm 一.什么是 SSL 证书,什么是 HTTPSSSL 证书是一种数字证书,它使用 Secure Socke ...
- linux下nginx配置ssl证书(https)
nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示: xxx.crt; #(证书公钥)xxx.key; #(证书私钥) 把这两个文件放到nginx的conf ...
- nginx配置ssl证书实现https访问
一,环境说明 服务器系统:ubuntu16.04LTS 服务器IP地址:47.89.12.99 域名:bjubi.com 二,域名解析到服务器 在阿里云控制台-产品与服务-云解析DNS-找到需要解析的 ...
- 阿里云 nginx配置ssl证书实现https访问
一,环境说明 服务器系统:ubuntu16.04LTS 服务器IP地址:47.89.12.99 域名:bjubi.com 二,域名解析到服务器 在阿里云控制台-产品与服务-云解析DNS-找到需要解析的 ...
随机推荐
- 一个极其高效的虚拟机内存冗余消除机制:UKSM
Linux内核机制KSM(Kernel Samepage Merging)能合并KVM虚拟机之间相同内存的页面,被CentOS, RHEL之类的服务器内核广泛采用,但是其速度很慢.UKSM(Ultra ...
- JQuery 获得元素的方法
获取一个元素的值可以有很多方式:<input type="text" id="txt" class="ipt" name=" ...
- 关于Cocos2d-x中精灵节点的透明度的设置
1.当我们需要某个精灵作为一个大一点的容器来存放其他的小精灵的时候,我们先设置这个精灵的大小 setTextureRect(Rect(0, 0, babySize.width, babySize.he ...
- Cocos2d-x模版卸载及安装
卸载:将隐藏的模板文件删除掉 首先打开你mac终端,然后输入如下命令:显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -b ...
- c++获取cpu信息
原文地址:http://blog.csdn.net/jamesliulyc/article/details/2028958 1.什么是cpuid指令 CPUID指令是intel IA32架构下获得CP ...
- linux nfs
linux(十四)之linux NFS服务管理 学到这里差不多就结束了linux的基础学习了,其实linux的内容并不难,我们要经常的反复的去操作它,多多和它去联络感情才能很好的掌握这个linux. ...
- 关于android 调用网页隐藏地址栏
首先创建项目,在main.xml里 添加好WebView控件R.id为webview1. HelloWebView.java 代码 package liu.ming.com; import andro ...
- Phpcms V9当前栏目及所有二级栏目下内容调用标签
在二级栏目列表页调用: <!--* 获取子栏目* @param $parentid 父级id* @param $type 栏目类型* @param $self 是否包含本身 0为不包含* @pa ...
- linux vi编辑器中,如何通过快捷键上下翻页?
需求说明: 之前在vi的时候,如果想看下一页,就直接按住 ↓ 这个箭头一直翻,现在觉得有些麻烦, 就找了下上,下翻页的快捷方式.在此记录下. 记录: 1.向下翻页快捷键(下一页):Ctrl + f 2 ...
- 在可部署到brew真机上的程序包构建完之后又要如何将该程序包发布到真机上呢
1.到brew官网上去申请含有classid的bid文件,以及.sig文件 2.根据申请到的bid文件重新生成mif文件. 3.将mif文件部署到brew真机上的mif文件夹下. 4.在真机上的bre ...