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

最新文章

  1. AngularJS2
  2. linux 下 sudo 指令不需要输入密码的配置
  3. android开发 缩放到指定比例的尺寸
  4. 彻底理解浮动float CSS浮动详解 清除浮动的方法
  5. spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
  6. C#事物
  7. 大白话Vue源码系列(04):生成render函数
  8. 模型加速[tensorflow&tensorrt]
  9. SQL Server 2014备份维护计划
  10. squid调整
  11. 如何在windows上调试安卓机谷歌浏览器上的页面
  12. Learning to rank的讲解,单文档方法(Pointwise),文档对方法(Pairwise),文档列表方法(Listwise)
  13. CURL操作
  14. webvtt字幕转srt字幕的python程序(附改名程序)
  15. layer使用
  16. Linux的时间设置与同步
  17. SVN版本服务器的搭建和远程控制
  18. Spring MVC处理响应的 header
  19. CF 577A 分解因数
  20. UVa 1210 连续素数之和

热门文章

  1. VS Code汉化
  2. A1121. Damn Single
  3. A1065. A+B and C (64bit)
  4. (转)Java并发编程:线程池的使用
  5. mysql数据库的优化和查询效率的优化
  6. quartz 每天0点5分开始,以后每隔15分钟启动一次,23:50停止
  7. 工具类:Colletions ,Arrays(静态导入,可变参数,强循环)
  8. Python基础语法总结
  9. hdu 3415"Max Sum of Max-K-sub-sequence"(单调队列)
  10. windows怎样查看被程序占用的端口