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-找到需要解析的 ...
随机推荐
- python中copy 与 '=' 的区别
当你a=1000的时候a指向一个新的类,内容为1000,而b仍然指向原来指向的内容,因为你没有叫它指向其他内容.你使用=符号,使得a和b指向同一个内容,而copy则是将b的内容复制后让c指向这个拷贝的 ...
- 利用VBA宏批量解决Word中图片大小、居中设置
需求:经常阅读网上的研报(没钱买排版漂亮的高质量研报),有些需要保存的复制下来到word里,图片很大都超出word的边界了,也没有居中,手工一张张调整不现实,上百页的研报,几十张图片. 解决方案:利用 ...
- get提交
<?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { //显示用户 public function index(){ $Use ...
- Cocos2d-x模版卸载及安装
卸载:将隐藏的模板文件删除掉 首先打开你mac终端,然后输入如下命令:显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -b ...
- activiti小结
前提:业务流程复杂且流程频繁变更的,建议使用工作流:其他情况不建议使用. activiti(v5.14),工作流引擎,基于jbpm.使用建模语言BPMN2.0进行定义. 工作流数据需要写入数据库,ac ...
- 资深投资人全力反击: VC增值平台从来就不是一坨狗屎
编者注: 本文来自海外著名科技博客VentureBeat, 英文原文出自Kyle Lacy之手 ,中文版由天地会珠海分舵进行编译. 文章主要是针对前几天德国VC Christian Claussen的 ...
- linux环境中,查询网卡的速度(带宽)
需求描述: 今天一同事要整理测试环境的主机硬件配置信息,需要提供网卡的速度的信息, 所以,就查询了下,在此记录下. 操作过程: 1.首先通过ip a命令查询主机的网口名称 [root@redhat6 ...
- brew 接口的原理
请查看相关文档的第9章 该文档可以csdn silentjesse帐号下的资源去下载 http://download.csdn.net/detail/silentjesse/5859077
- [extjs] extjs 5.1 API 开发 文档
官方博客发布了这个新版本说明,英文文章请戳下面 http://www.sencha.com/blog/announcing-sencha-ext-js-5.1/ 翻译版本请戳下面: http://ex ...
- JavaScript------去掉Array中重复值
转载: http://blog.csdn.net/teresa502/article/details/7926796 代码: // 删除数组中重复数据 function removeDuplElem( ...