nginx反向代理服务器以及负载均衡,从安装到配置
nginx的具体作用不用细说,很强大,做负载均衡、反向代理服务器解决前端跨域问题等等。下面是nginx的安装过程
首先nginx主要的依赖:
pcre、 pcre-devel
zlib zlib-devel
openssl openssl-devel
因此安装nginx需要安装以下依赖(本教程只介绍centos在线安装,离线安装见另一篇文章)
1.安装依赖
yum install gcc
yum install pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
2.下载解压nginx
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz (解压文件)
3.安装nginx
//进入nginx目录
cd /usr/local/nginx-1.13.7
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install
4.配置nginx
cd到nginx配置文件,配置相应的信息数据,主要是配置好upstream 以及server即可,现在贴出我本机的配置
cd /usr/local/nginx/conf
vim nginx.conf
5.测试nginx是否配置正确
/usr/local/nginx/sbin/nginx -t
如果出现以下所示,则配置没有问题
6.nginx的启停
启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
其他介绍
1.VIM语法
默认vim打开后是不能录入的,需要按键才能操作,具体如下:
开启编辑:按“i”或者“Insert”键
退出编辑:“Esc”键
退出vim:“:q”
保存vim:“:w”
保存退出vim:“:wq”
不保存退出vim:“:q!”
2.nginx配置语法介绍
#user nobody; #开启进程数 <=CPU数
worker_processes 1; #错误日志保存位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #进程号保存文件
#pid logs/nginx.pid; #每个进程最大连接数(最大连接=连接数x进程数)每个worker允许同时产生多少个链接,默认1024
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压缩
#gzip on; server {
#监听端口,默认是80端口
listen 80;
#监听域名
server_name localhost; #charset koi8-r; #nginx访问日志放在logs/host.access.log下,并且使用main格式(还可以自定义格式)
#access_log logs/host.access.log main; #如果没有location更明确的匹配访问路径的话,访问请求都会被该location处理。
location / {
#root指定nginx的根目录为/usr/local/nginx/html
root html;
#默认访问文件,欢迎页先去html目录下找index.html,如果找不到再去找index.htm
index index.html index.htm;
} #error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# #错误页面及其返回地址,错误码为500、502、503、504都会返回50.html错误页面。
error_page 500 502 503 504 /50x.html;
#location后面是"="的话,说明是精确匹配
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
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.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;
# }
#} } --------------------- 本文来自 PengTDY 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/yougoule/article/details/78186138?utm_source=copy
No mapping for the Unicode character exists in the target multi-byte code page
使用windows版本的nginx启动时遇到(1113: No mapping for the Unicode character exists in the target multi-byte code page)这个错误
后来查阅资料发现是因为解压的路径里面包含有中文的缘故,只要把解压后的文件剪切到没有包含中文的目录即可解决问题
nginx反向代理服务器以及负载均衡,从安装到配置的更多相关文章
- 简单聊聊不可或缺的Nginx反向代理服务器--实现负载均衡【上篇】
今天又是新的一周,我养足了精神去对待新一周的工作,但是今天到公司发现还是有一点空闲时间的,所以就想与之前接触过的Nginx再交往得更深一点儿. 什么是Nginx: Nginx是一款高性能的http服务 ...
- Nginx反向代理服务器、负载均衡和正向代理
Nginx("engine x")是一个高性能的 HTTP 和反向代理服务器,第一个公开版本 0.1.0 发布于 2004 年 10 月 4 日.官方测试 nginx 能够支撑5万 ...
- Nginx反向代理,负载均衡,redis session共享,keepalived高可用
相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此 ...
- 【转】Nginx反向代理和负载均衡
原文链接:http://www.cnblogs.com/shuoer/p/7820899.html Nginx反向代理和负载均衡 环境说明 由于我使用的是windows系统,所以我用虚拟机虚拟出来了3 ...
- Nginx反向代理、负载均衡及日志
Nginx反向代理.负载均衡及日志 1.原理图 2.正向代理与反向代理 (1)代理服务器 代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送给代理服务器,代理服务接受客户机请求之后 ...
- Nginx反向代理与负载均衡应用实践(二)
Nginx反向代理与负载均衡应用实践(二) 链接:https://pan.baidu.com/s/1xB20bnuanh0Avs4kwRpSXQ 提取码:migq 复制这段内容后打开百度网盘手机App ...
- Nginx反向代理与负载均衡应用实践(一)
Nginx反向代理与负载均衡应用实践(一) 链接:https://pan.baidu.com/s/1xB20bnuanh0Avs4kwRpSXQ 提取码:migq 复制这段内容后打开百度网盘手机App ...
- Nginx反向代理实现负载均衡配置图解
Nginx反向代理实现负载均衡配置图解 [导读] 负载均衡配置是超大型机器需要考虑的一些问题,同时也是数据安全的一种做法,下面我来介绍在nginx中反向代理 负载均衡配置图解,大家可参考本文章来操作. ...
- 一篇文章搞定 Nginx 反向代理与负载均衡
代理 要想弄明白反向代理,首先要知道啥是正向代理,要搞懂正向代理只需要知道啥是代理即可.代理其实就是一个中介,在不同事物或同一事物内部起到居间联系作用的环节.比如买票黄牛,房屋中介等等. 在互联网中代 ...
随机推荐
- [题解] [BZOJ4144] 「AMPPZ2014」Petrol
题面 怎么是权限题啊 题解 有一次考过, 但是不记得了 如果每个点都是加油站的话, 这道题就是货车运输 考虑如何转化 我们可以设
- Exception in thread "main" java.util.ConcurrentModificationException解决方案
我想判断一个集合里面有没有"world"这个元素,如果有,我就添加一个"javaee"元素, 当时的做法是: public class ListIterator ...
- JMeter压力测试及并发量计算-1
一.JMeter的安装(Linux) 1. 下载JMeter:这个就不细说了,直接去(http://jmeter.apache.org/download_jmeter.cgi)下载. 2. 解压:ta ...
- Vue于React特性对比(四)
新开了一个vue的项目,从vue单页面框架搭建到单点登录接入都是自己负责搞的.然后准备将这套东西迁移到react上.然后有了这篇文章. 1,reactjs分环境打包明显要比vue更为麻烦 vue修改的 ...
- iOS如何将RGB565的原始图像数据转为UIImage对象
我们在做一些图像处理时,往往会涉及到RGB565这种图像数据格式.由于其每个像素仅占2个字节,对于不需要像素透明度的情况下使用RGB565既能基本能保证图像的色彩,又能降低图像数据尺寸,节省带宽.因此 ...
- MySQL表的创建与维护
一.导入测试数据 [root@server ~]# wget https://launchpadlibrarian.net/24493586/employees_db-full-1.0.6.tar.b ...
- Node.js使用Express实现Get和Post请求
var express = require('express'); var app = express(); // 主页输出 "Hello World" app.get('/', ...
- Spring Aop(一)——Aop简介
转发地址:https://www.iteye.com/blog/elim-2394629 1 Aop简介 AOP的全称是Aspect Oriented Programming,翻译成中文是面向切面编程 ...
- iOS-ShareSDK的使用(转)
官方下载ShareSDK iOS:http://sharesdk.cn/ ShareSDK社会化分享 包含“社会化分享组件”“社会化登录组件”“第三方评论和赞”三大模块,并有详尽的数据统计后台,助力移 ...
- Dart Language samples
Hello World Every app has a main() function. To display text on the console, you can use the top-lev ...