1、创建nignx用户

/usr/sbin/groupadd -f nginx
/usr/sbin/useradd -g nginx nginx

2、安装依赖

yum install gcc  gcc-c++ -y #默认有的话无须安装
yum install -y pcre-devel openssl-devel #依赖(支持Nginx服务访问,以https方式访问)

3、下载软件包&编译安装

wget -q http://nginx.org/download/nginx-1.14.2.tar.gz #下载软件包
tar xf nginx-1.14..tar.gz
cd nginx-1.14.
./configure --prefix=/usr/local/nginx-1.14. --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module #根据你的需求添加编译时要带的模块
make && make install

4、软链接启动

ln -s /usr/local/nginx-1.14. /usr/local/nginx
# 这条ln命令的意义十分深远重大。这是生产环境的经验。
# 将Nginx安装路径通过软链接方式更改为/usr/local/nginx/,方便人员使用。
# 安装时指定版本号路径是为了便于查看分区当前使用的版本,也方便以后升级。
/usr/local/nginx/sbin/nginx #启动nginx 若报错说明没有创建nginx用户或者是
ln -s /usr/local/nginx-1.14./sbin/nginx /usr/local/sbin/ #做条软连接直接用nginx启动
在nginx.conf中 把user nobody的注释去掉既可
netstat -lntup|grep 查看是否有80端口

5、查看nginx的编译参数

#/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.14.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module

6、检查语法&平滑重启

nginx -t   #检查语法是否正常
nginx -s reload #平滑重启

7、精简nginx配置文件

egrep -v "#|^$" nginx.conf.default >nginx.conf  #精简化/最小化默认nginx.conf配置文件信息

8、配置nginx负载均衡

# vim conf/nginx.conf
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
upstream wang.com{ #服务器集群的名字
server 10.10.16.223: weight=;
server 10.10.16.252: weight=; }
server {
listen ;
server_name localhost;
location / {
proxy_pass http://wang.com; #以上面对应
proxy_redirect default;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}

  标准的配置请写在vhost下面:

[root@linux-node1 conf]# cat nginx.conf
#user www;
worker_processes auto;
worker_rlimit_nofile ; events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ; log_format main '$remote_addr - $host [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_addr $upstream_status $upstream_response_time $bytes_sent'; gzip on ;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml application/json application/javascript text/javascript image/jpeg image/gif image/png;
gzip_disable "MSIE [1-6].";
gzip_vary on;
#其他的在着重添加优化参数 include vhost/*.conf; }

  处理逻辑的放在vhost下面:

[root@shenzhen conf]# pwd
/usr/local/nginx/conf
[root@shenzhen conf]# cat vhost/gunicorn.conf
server {
listen ;
server_name xx.xxx.xxx.xxx; #location / {
# root html;
# index index.html index.htm;
# } location / {
proxy_pass http://127.0.0.1:5001;
proxy_redirect default;
} error_page /50x.html;
location = /50x.html {
root html;
} access_log /data/logs/nginx/gunicorn_access.log main;
error_log /data/logs/nginx/gunicorn_error.log; }

9、终结版

  一键安装openresty,配置优化等

[root@linux-node1 ~]# cd /usr/local/src
[root@linux-node1 src]# git clone https://github.com/unixwang/linux-package.git
[root@linux-node1 src]# cd linux-package/
[root@linux-node1 linux-package]# yum localinstall -y jemalloc-4.5.-.x86_64.rpm openresty-1.15.8.1-.x86_64.rpm
[root@linux-node1 vhost]# cd /usr/local/openresty/nginx/conf/vhos
[root@linux-node1 vhost]# /usr/local/openresty/nginx/sbin/nginx

快速安装nginx的更多相关文章

  1. CentOS 6.4 快速安装Nginx笔记

    CentOS 6.4 快速安装Nginx笔记 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/9860 ...

  2. 在Mac OS X 下快速安装Nginx

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Helvetica; color: #8e68ff } p.p2 { margin: 0.0p ...

  3. CentOS用yum快速安装nginx

    增加nginx源 vim  /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/ ...

  4. centos7下快速安装Nginx服务器

    1.添加源 默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址.因此可以如下执行命令添加源: sudo rpm -Uvh http://nginx.org/pa ...

  5. Centos下快速安装Nginx

    1.准备工作 选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL. Nginx是C写的,需要用GCC编译:Ngin ...

  6. 快速安装Nginx及配置详解(未完待续)

    导读: Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,从2007年被德国人开发出来后可以说在市场的占有率一路飙升,因为它支持高并 ...

  7. CentOS快速安装Nginx的方法,nginx如何启动重启停止

    1.防止 make: command not found,提前安装一些插件,取决于当前环境是否已安装,如果已经安装就不需要执行此命令 yum -y install gcc automake autoc ...

  8. Nginx的快速安装

    1. 准备工作 1. CenterOS7.x.vmware虚拟机,安装过程参考 https://jingyan.baidu.com/article/eae0782787b4c01fec548535.h ...

  9. zabbix快速安装(Ubuntu18.04, Nginx)

    ubuntu18.04快速安装zabbix4.0 https://blog.csdn.net/qq_33317586/article/details/83867756 需要安装的东西:nginx,ph ...

随机推荐

  1. Redis在python中的使用

    一 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...

  2. io系列之其他类

    一.File类:将文件或者文件夹封装成对象. 方便对文件和文件夹的属性信息进行操作. File对象可以作为参数传递给流的构造函数. 注意: 文件夹名称也可带有扩展名. 构造函数: File(Strin ...

  3. Day30--Python--struct, socketserver

    1. struct struct.pack 打包 def pack(fmt, *args): # known case of _struct.pack """ pack( ...

  4. Day3--Python--字符串,for循环,迭代

    常见的基本数据类型: 1.int 整数 主要用来进行数学运算 2.bool 布尔. 判断真假. if 和 while循环中常用 3.str 字符串,一般放小量数据 4.list 列表.可以存放大量的数 ...

  5. Freemarker 的 Eclipse 插件 安装

    clipse版本(目前最新oxygen) 如果你的eclipse版本为Oxygen "Help" ---> "Eclipse Marketplace..." ...

  6. Good Bye 2018 C. New Year and the Sphere Transmission

    传送门 https://www.cnblogs.com/violet-acmer/p/10201535.html 题意: n 个people,编号1~n,按顺时针方向围城一圈: 初始,编号为1的peo ...

  7. AndroidS软件代码提示

    在用Eclipse时候,你可以进行设置,设置成不管你输入任何字母,都能进行代码的提示,在Android Studio中也可以 设置,而且比Eclipse设置来的简单.当然如果你觉得代码自动提示会降低你 ...

  8. JS实现选择排序

    function selectSort(arr){ var len=arr.length; var temp; for(var i=0;i<len-1;i++){ for(var j=i+1;j ...

  9. collections 模块之Counter

    Counter字典的子类,用于统计哈希对象 from collections import Counter users = ["body1","body11", ...

  10. springmvc上传图片《2》

    创建springboot项目 编写配置 server: port: 8082 spring: application: name: upload-service servlet: multipart: ...