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-找到需要解析的 ...
随机推荐
- 判断asp.net中session过期的方法
判断asp.net中session过期的方法 转载自:http://www.cnblogs.com/xilipu31/archive/2013/04/12/3016830.html 方法一:最麻烦也是 ...
- Hbase建模
转自:http://blog.itpub.net/28912557/viewspace-1119865/ 什么情况下使用Hbase?1,成熟的数据分析主题,查询模式已经确定并且不易轻易改变.(主要还是 ...
- 更改HDFS权限
hdfs dfs -chmod -R 755 / 之前执行过这条语句,但是总是提示: 15/05/21 08:10:18 WARN util.NativeCodeLoader: Unable to l ...
- Ubuntu创建新用户并增加管理员权限 删除某个用户
sudo adduser xxx 这样的命令会在home目录下添加一个帐号sudo useradd xxx 仅仅是添加用户, 不会在home目录添加帐号 删除:终端方法:以下用newuser代替想要删 ...
- 仿教程 小爬虫抓取imooc数据
慕课网的nodejs教程:http://www.imooc.com/learn/348 这人讲的很赞,特别是在事件驱动这点上,耳目一新. 视频略老,所以demo有些过时了,摸索着写了一个自己的小程序. ...
- 奇怪的bug:javascript不执行
背景:有人想要个简单的js效果,点击某个菜单,其他菜单收起. 说了下思路,结果~~ 只好直接写了一个,代码如下: <!DOCTYPE html> <html> <head ...
- Netstat命令(windows下)
功能: 一般用于检验本机各端口的网络连接情况. 例子:检查本机3389远程连接端口是否可用 netstat -nao|find "3389" 查看某进程使用的端口号: netst ...
- pyqt二进制和图片的转换
参考:http://blog.chinaunix.net/uid-28194872-id-3516936.html MySQL数据库要想插入图片,其字段需要是BLOB类型.BLOB (binary l ...
- sqlserver 字符串split
select value from TF_NJVALUES('3C457A2D-188B-4D99-A822-2968054E1FB8,3C457A2D-188B-4D99-A822-2968054E ...
- chrome浏览器默认启动时打开2345导航的解决方法
2345并没有改动chrome内部设置.它仅仅是把全部的快捷方式改动了.包含開始菜单旁边的快捷启动图标. 仅仅须要右键chrome快捷方式.在目标一栏中,把"----chrome.exe&q ...