首页 技术 正文
技术 2022年11月9日
0 收藏 832 点赞 4,273 浏览 1806 个字

Nginx 是一款高性能的Web服务器软件.

– 具有极高的并发性能

– 利用Nginx与Tomcat组合使用, 搭建反向代理集群

– Nginx 反向代理集群可以解决网站的高并发问题!

1、安装

Yum安装

安装

yum -y install nginx

启动、停止、重启、开机自启

systemctl start|stop | restart | enable  nginx.service

检查进程

ps  -aux|grep nginx

源码编译安装

下载源代码

wget http://nginx.org/download/nginx-1.12.2.tar.gz

创建nginx用户

useradd nginx

创建nginx安装目录

mkdir /usr/local/nginx

安装编译时候的依赖包

yum -y install pcre-devel openssl openssl-devel

解压并且编译

tar -zxf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure –prefix=/usr/local/nginx –user=nginx  –with-http_ssl_module

make

make install

运行nginx

nginx -c /usr/local/nginx/conf/nginx.conf

检查进程

ps  -aux|grep nginx

2、配置
nginx配置文件位置

编译安装版本
/usr/local/nginx/conf/nginx.conf
yum安装版本
/etc/nginx/nginx.conf

nginx配置文件结构

通用(全局)配置参数http{
http 协议通用参数 server{
虚拟机配置参数
} server{
虚拟机配置参数
}}

3、虚拟主机

在一个Web服务器上通过服务器软件模拟多台Web 服务器, 其中每个虚拟的Web服务器称为一个虚拟主机. 虚拟主机的好处是可以充分复用同一个web服务器. 对于用户来说, 用户感觉是多个网站.

Nginx 配置文件中 每个 server{} 块对应一个虚拟主机

虚拟主机有3种:

  1. 基于域名的虚拟主机(最常用的虚拟主机)

    • 需要为服务器指定多个域名
    • 域名资源解析方便, 便于用户记忆, 用户体验好.
  2. 基于IP虚拟主机
    • 需要为服务器指定多个IP地址
    • 需要租用IP
    • 很少使用这种方式
  3. 基于端口的虚拟主机
    • 绑定到服务器的多个端口
    • 默认80端口只有一个
    • 使用其他端口号提供服务, 因为用户需要记忆端口, 用户的体验差

请求 t1.canglaoshi.org 访问 t1文件夹 index.html文件
server{
    listen 80;
    server_name t1.canglaoshi.com;
    location / {
    root t1;
    index index.html;
    }
}
在Nginx文件夹/usr/local/nginx中添加新文件夹t1和文件index.html
测试:
http://t1.canglaoshi.com

4、https加密访问
1. 下载证书文件到 /usr/local/nginx/conf/cert
2. 更新 nginx.conf 的配置, 并且测试配置文件
3. 重新启动Nginx
4. 在客户端配置域名解析
5. 利用客户端访问 https://test.canglaoshi.com

nginx.conf

test.conf

server{
listen 80;
server_name test.canglaoshi.com;
return 301 https://test.canglaoshi.com;
}server{
listen 443;
server_name test.canglaoshi.com; ssl on; ssl_certificate cert/xxxxxxxxxxxxx.pem;
ssl_certificate_key cert/xxxxxxxxxxxxx.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root test;
index index.html;
}
}

重启nginx访问https://test.canglaoshi.com 即可

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905