linux系统为Centos 64位

一、安装

[root@cuiqq local]# mkdir /usr/local/nginx
[root@cuiqq local]# cd /usr/local/nginx/
[root@cuiqq nginx]# wget http://nginx.org/download/nginx-1.17.5.tar.gz
[root@cuiqq nginx]# tar -zxvf nginx-1.17.5.tar.gz
[root@cuiqq nginx]# cd nginx-1.17.5
[root@cuiqq nginx-1.17.5]# ./configure 
[root@cuiqq nginx-1.17.5]# make install
[root@cuiqq bin]# cd /usr/local/nginx/
[root@cuiqq nginx]# rm -rf nginx-1.17.5 nginx-1.17.5.tar.gz
[root@cuiqq nginx]# cp sbin/nginx /usr/local/bin/
[root@cuiqq nginx]# nginx
[root@cuiqq nginx]# ps -ef | grep nginx
root 19784 1 0 00:48 ? 00:00:00 nginx: master process nginx
nobody 19785 19784 0 00:48 ? 00:00:00 nginx: worker process
root 20146 20751 0 00:48 pts/1 00:00:00 grep nginx
======安装完成=====

二、nginx命令

进入/sbin 目录后执行命令:

nginx启动
、启动nginx:nginx
、关闭nginx:nginx -s stop
、重启nginx:nginx -s reload

多种停止方式:

停止操作是通过向nginx进程发送信号来进行的

查询nginx主进程号

ps -ef | grep nginx
root 20191 1 0 21:00 ? 00:00:00 nginx: master process nginx
nobody 20192 20191 0 21:00 ? 00:00:00 nginx: worker process

在进程列表里 面找master进程,它的编号就是主进程号了。

发送信号从容停止Nginx

kill -QUIT 主进程号

快速停止Nginx

kill -TERM 主进程号

强制停止Nginx

pkill - nginx

另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginx的logs目录下。有了pid文 件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:
kill -信号类型 '/usr/nginx/logs/nginx.pid'

平滑重启

如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。
平滑重启命令:
kill -HUP 主进程号或进程号文件路径

或者使用

/usr/nginx/sbin/nginx -s reload

注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。

判断Nginx配置是否正确命令

nginx -t -c /usr/nginx/conf/nginx.conf

或者

/usr/nginx/sbin/nginx -t

[root@cuiqq conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

三、配置nginx.conf

nginx配置分为五大区域,main、event、http、service、location。我们常用的是后面三个

作用:全局作用域

##全局块 开始##

user nobody; #配置允许运行nginx服务器的用户和用户组,这里的nobody就是上面查看nginx进程时显示的nobody

worker_processes number  | auto ; #nginx进程参数,通常设置成和CPU的数量相等 也可以设置成auto 演示v5

error_log logs/error.log; #错误日志存放路径

#error_log logs/error.log notice;

#error_log logs/error.log info;

pid logs/nginx.pid; #nginx pid记录位置

##全局块 结束##

Event块配置

作用:Nginx服务器与用户的网络连接

events {

worker_connections  1024; #连接数上限,单个后台进程最大并发链接数默认1024

use epoll; #工作模式:epoll多路复用IO中的一种方式,仅适用于linux2.6以上内核,提高nginx性能 uname –a 查看linux内核

}

  1 user www www;
2 # 工作进程个数,可配置多个
3 worker_processes auto;
4
5 error_log /data/wwwlogs/error_nginx.log crit;
6 pid /var/run/nginx.pid;
7 worker_rlimit_nofile 51200;
8
9 events {
10 use epoll;
11 # 单个进程最大连接数
12 worker_connections 51200;
13 multi_accept on;
14 }
15
16 http {
17 include mime.types;
18 default_type application/octet-stream;
19 server_names_hash_bucket_size 128;
20 client_header_buffer_size 32k;
21 large_client_header_buffers 4 32k;
22 client_max_body_size 1024m;
23 client_body_buffer_size 10m;
24 sendfile on;
25 tcp_nopush on;
26 keepalive_timeout 120;
27 server_tokens off;
28 tcp_nodelay on;
29
30 fastcgi_connect_timeout 300;
31 fastcgi_send_timeout 300;
32 fastcgi_read_timeout 300;
33 fastcgi_buffer_size 64k;
34 fastcgi_buffers 4 64k;
35 fastcgi_busy_buffers_size 128k;
36 fastcgi_temp_file_write_size 128k;
37 fastcgi_intercept_errors on;
38
39 #Gzip Compression
40 gzip on;
41 gzip_buffers 16 8k;
42 gzip_comp_level 6;
43 gzip_http_version 1.1;
44 gzip_min_length 256;
45 gzip_proxied any;
46 gzip_vary on;
47 gzip_types
48 text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
49 text/javascript application/javascript application/x-javascript
50 text/x-json application/json application/x-web-app-manifest+json
51 text/css text/plain text/x-component
52 font/opentype application/x-font-ttf application/vnd.ms-fontobject
53 image/x-icon;
54 gzip_disable "MSIE [1-6]\.(?!.*SV1)";
55
56 #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
57 open_file_cache max=1000 inactive=20s;
58 open_file_cache_valid 30s;
59 open_file_cache_min_uses 2;
60 open_file_cache_errors on;
61
62 ######################## default ############################
63 # 服务器集群名称自定义的 和下面的location地址对应
64 upstream myServer {
65 # weigth参数表示权值,权值越高被分配到的几率越大
66 # server 127.0.0.1:8080 weight=1;
67 # server 127.0.0.1:8060 weight=1;
68 server 47.93.10.184:8080;
69 server 47.93.10.184:8081;
71 }
72
73 # 每一个server相当于一个代理服务器
74 server {
75 # 监听端口,默认80
76 listen 8848;
77 # 当前服务的域名,可以有多个,用空格分隔(我们是本地所以是localhost) www.cuiqq.cn 也可以是 ip
78 server_name localhost;
79 #server_name _;
80 access_log /data/wwwlogs/access_nginx.log combined;
81 root /data/wwwroot/default;
82 # 当没有指定主页时,默认会选择这个指定的文件,可多个,空格分隔
83 index index.html index.htm index.php;
84 # 表示匹配的路径,这时配置了/表示所有请求都被匹配到这里 ***重点:路径匹配规则会有单独一节说明***
85 location / {
86 # 请求转向自定义的服务器列表
87 proxy_pass http://myServer;
88 }
89 location /nginx_status {
90 stub_status on;
91 access_log off;
92 allow 127.0.0.1;
93 deny all;
94 }
95 location ~ [^/]\.php(/|$) {
96 #fastcgi_pass remote_php_ip:9000;
97 fastcgi_pass unix:/dev/shm/php-cgi.sock;
98 fastcgi_index index.php;
99 include fastcgi.conf;
100 }
101 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
102 expires 30d;
103 access_log off;
104 }
105 location ~ .*\.(js|css)?$ {
106 expires 7d;
107 access_log off;
108 }
109 location ~ /\.ht {
110 deny all;
111 }
112 }
113
114 ########################## conf.d #############################
115 include conf.d/*.conf; ##将另外一个文件包含到当前文件中,一般会放一些 upstream
116 }


负载均衡(三)Nginx的安装配置的更多相关文章

  1. java:tomcat(负载均衡)nginx的应用配置

    http://mini.eastday.com/mobile/180627012211514.html 1.什么是负载均衡 由于系统各个核心部分随着业务量的提高,访问量和数据流量的快速增长,单一的服务 ...

  2. Nginx的安装配置和tomcat负载均衡

    Nginx简介 什么是nginx? Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试ngi ...

  3. Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理

    通过我们会用Nginx的upstream做基于http/https端口的7层负载均衡,由于Nginx老版本不支持tcp协议,所以基于tcp/udp端口的四层负载均衡一般用LVS或Haproxy来做.至 ...

  4. Dubbo入门到精通学习笔记(十四):ActiveMQ集群的安装、配置、高可用测试,ActiveMQ高可用+负载均衡集群的安装、配置、高可用测试

    文章目录 ActiveMQ 高可用集群安装.配置.高可用测试( ZooKeeper + LevelDB) ActiveMQ高可用+负载均衡集群的安装.配置.高可用测试 准备 正式开始 ActiveMQ ...

  5. 大数据高并发系统架构实战方案(LVS负载均衡、Nginx、共享存储、海量数据、队列缓存)

    课程简介: 随着互联网的发展,高并发.大数据量的网站要求越来越高.而这些高要求都是基础的技术和细节组合而成的.本课程就从实际案例出发给大家原景重现高并发架构常用技术点及详细演练. 通过该课程的学习,普 ...

  6. 反向代理负载均衡之nginx

    一.集群 1.1 什么是集群 集群是一组相互独立的.通过高速网络互联的计算机,它们构成了一个组,并以单一系统的模式加以管理.一个客户与集群相互作用时,集群像是一个独立的服务器.集群配置是用于提高可用性 ...

  7. Nginx 的安装配置入门(mac)

    1.安装Nginx服务器: 执行命令 brew install nginx 安装完以后,可以在终端输出的信息里看到一些配置路径: /usr/local/etc/nginx/nginx.conf (配置 ...

  8. 动态负载均衡(Nginx+Consul+UpSync)

    Http动态负载均衡 什么是动态负载均衡 传统的负载均衡,如果Upstream参数发生变化,每次都需要重新加载nginx.conf文件, 因此扩展性不是很高,所以我们可以采用动态负载均衡,实现Upst ...

  9. nginx初级安装配置

    nginx初级安装配置 转自:(lykyl原创)http://www.cnblogs.com/lykyl/archive/2012/11/21/2781077.html 实验环境:系统 CENTOS5 ...

  10. nginx php-fpm安装配置 CentOS编译安装php7.2

    CentOS编译安装php7.2 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说.如果你是升级或新安装,那你首先需要考虑php7和程序是 ...

随机推荐

  1. ASP.NET MVC 发布WIN SERVER2012

    首先在打开服务器管理,点添加角色和功能 这个名字自己设置不打紧 勾选web服务器,之后点下一步 在功能选择中勾选下面部分 之后点击工具选择服务,确保web服务正在运行 此时服务端告一段落,返回主机打开 ...

  2. 2 Configuring SAP ERP Sales and Distribution -introduction to SAP

    First Steps in SAPWe’ll now discuss some of the basic menus, screens, and transactions that you need ...

  3. 【HR系列】SAP HR PA信息类型的创建与增强

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HR系列]SAP HR PA信息类型的创建与增 ...

  4. Spring Boot 中使用 WebSocket 实现一对多聊天及一对一聊天

    为什么需要WebSocket? 我们已经有了http协议,为什么还需要另外一个协议?有什么好处? 比如我想得到价格变化,只能是客户端想服务端发起请求,服务器返回结果,HTTP协议做不到服务器主动向客户 ...

  5. 【转帖】如何看待 HTTP/3 ?

    如何看待 HTTP/3 ? https://mp.weixin.qq.com/s/fC10Cyj6xjjwOCnqxX-Dvg 车小胖的公众号 转帖学习一下. 原创: 车小胖谈网络 车小胖谈网络 20 ...

  6. seata demo

    0. 介绍 2019 年 1 月,阿里巴巴中间件团队发起了开源项目 Fescar(Fast & EaSy Commit And Rollback),和社区一起共建开源分布式事务解决方案.Fes ...

  7. 【6.28校内test】T1 Jelly的难题1

    Jelly的难题[题目链接] 废话一句:今天中考出成绩,感觉大家考的都超级棒,不管怎样,愿大家成为最好的自己. 好了废话完了,下面是题解部分: SOLUTION: 首先你可能发生的,是看不懂题: 定睛 ...

  8. Luogu P1631 序列合并

    题目 开一个堆,先把所有\(a[i]+b[1]\)压进优先队列. 然后每次把最小的取出来,把对应的\(a[i]\)的下一个\(b[j]\)拿出来加进去. #include<bits/stdc++ ...

  9. window下的php命令行输出汉字乱码处理

    1. 在php的代码中加入 header("content-type:text/html;charset=gbk"); 2. 设置命令行的字体 在命令行上右击属性 字体 选择如下字 ...

  10. 使用iwebshop開發實現QQ第三方登錄

    $appid = "101353491"; $appkey = "df4e46ba7da52f787c6e3336d30526e4"; $redirect_ur ...