Nginx使用介绍

最近谣言比较多,危机感爆棚,开始对过去一年工作中的一些知识做一些小结。

Nginx作为一个高性能的Web服务器被广泛使用,目前在我们项目中,也使用了Nginx来做Web服务和反向代理,主要记录下日常使用

安装

下载源码安装,下载地址:http://nginx.org/en/download.html

由于是客户生产环境,没有采用最新版本,采用的1.14.x 版本

1、安装依赖

yum install openssl-devel pcre pcre-devel -y

2、创建用户

useradd nginx -s /sbin/nologin -M

3、上传源码包到/usr/local/src

-rw-r--r-- 1 root root 1015384 Apr 23  2019 nginx-1.14.2.tar.gz

4、解压安装

[root@rocketmq-2 src]# tar -zxvf nginx-1.14.2.tar.gz 

5、进入解压后的目录

[root@rocketmq-2 src]# cd nginx-1.14.2/

[root@rocketmq-2 nginx-1.14.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.14.2 --with-http_stub_status_module --with-http_ssl_module

[root@rocketmq-2 nginx-1.14.2]# make && make install

[root@rocketmq-2 ~]# cd /usr/local/
[root@rocketmq-2 local]# ln -s nginx-1.14.2 nginx

配置

安装完成后进行配置,
配置文件:/usr/local/nginx/conf/nginx.conf

1、进入配置文件目录

[root@rocketmq-2 local]# cd /usr/local/nginx/conf/
[root@rocketmq-2 conf]# grep -Ev '^$|#' nginx.conf.default > nginx.conf

下面是默认配置文件,已删除空行和注释行
[root@rocketmq-2 conf]# vim nginx.conf

worker_processes  1;
events {
  worker_connections  1024;
}
http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  server {
      listen       80;
      server_name  localhost;
      location / {
          root   html;
          index  index.html index.htm;
      }
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   html;
      }
  }
}

默认监听80端口
检查配置文件是否正确命令:

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

启动服务: 默认一个master和一个worker进程

[root@rocketmq-2 conf]# ps -ef|grep nginx
root       7449      1  0 22:06 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      7450   7449  0 22:06 ?        00:00:00 nginx: worker process
root       7452   7223  0 22:06 pts/0    00:00:00 grep --color=auto nginx
[root@rocketmq-2 conf]# 
[root@rocketmq-2 conf]# 
image.png

平滑重启

nginx -s reload

停止

nginx -s stop

pkill nginx

检查版本

[root@rocketmq-2 conf]# ../sbin/nginx -v
nginx version: nginx/1.14.2
[root@rocketmq-2 conf]# 
[root@rocketmq-2 conf]# 
[root@rocketmq-2 conf]# 
[root@rocketmq-2 conf]# ../sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx-1.14.2 --with-http_stub_status_module --with-http_ssl_module --with-http_mp4_module
[root@rocketmq-2 conf]# 
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容