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-找到需要解析的 ...
随机推荐
- javascript 复制与粘贴操作
<script language="javascript"> function readTxt() { alert(window.clipboardData.getDa ...
- 介绍Unity中相机的投影矩阵与剪切图像、投影概念
这篇作为上一篇的补充介绍,主要讲Unity里面的投影矩阵的问题: 上篇的链接写给VR手游开发小白的教程:(三)UnityVR插件CardboardSDKForUnity解析(二) 关于Unity中的C ...
- linux -- Ubuntu报错“unable to locate package...”
有时候在Ubuntu命令行中执行安装某个文件的时候,如:sudo apt-get install xinit ,报 “unable to locate package...” 错误,解决办法如下 1. ...
- Java调用FTP实例
package com.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStre ...
- 系统管理员应该知道的20条Linux命令
如果您的应用程序不工作,或者您希望在寻找更多信息,这 20 个命令将派上用场. 在这个全新的工具和多样化的开发环境井喷的大环境下,任何开发者和工程师都有必要学习一些基本的系统管理命令.特定的命令和工具 ...
- u3d change terrain textrue&height
using UnityEngine; using System.Collections; public class terrainTest : MonoBehaviour { ; private Te ...
- LR中点鼠标做关联(winsock协议)
转自:http://blog.csdn.net/zeeslo/article/details/1661791 今天写一下winsock的关联操作. 以前看过一个文档.在英文版的讲winsock的,其中 ...
- 关于NaN(Not a Number)的问题
在游戏运行时,代码若写得不安全很容易出现NAN的异常.一旦NAN出现整个游戏不崩溃也坏死掉了,游戏上了则是要被直接打回来的节奏,更是一个开发及测试人员每人都要扣3000块的大BUG. 一般表现为: ...
- AOPR密码过滤器
在Advanced Office Password Recovery任一攻击的破解选项设置窗口都有一个“编辑密码过滤器”按钮,设置好AOPR密码破解工具的密码过滤器可以大大提高破解速度,下文将具体介绍 ...
- 记录下自己常用的全框架HTML代码
纯粹记录下,没有任何意义. 也不推荐使用 <frameset rows="> <frame src=" name="topFrame" scr ...