CentOS安装nginx

1、下载安装包

下载地址:http://nginx.org/en/download.html
如果是测试环境,下载什么版本都可以,如果是生产环境的话,最好还是下载最新的稳定版本(Stable version)

在这里下载最新的稳定版本

2、安装依赖

[root@140106 soft]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

3、解压安装包

[root@140106 soft]# tar -zxvf nginx-1.15.10.tar.gz
[root@140106 soft]# cd nginx-1.15.10

4、配置编译安装

[root@140106 nginx-1.15.10]# ./configure  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module


[root@140106 nginx-1.15.10]# ./make
[root@140106 nginx-1.15.10]# make install
nginx大部分常用模块,编译时./configure --help以--without开头的都默认安装。

--prefix=PATH : 
	指定nginx的安装目录。默认 /usr/local/nginx
--conf-path=PATH : 
	设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,
	通过命令行中的-c选项。默认为prefix/conf/nginx.conf
--user=name: 
	设置nginx工作进程的用户。安装完成后,
	可以随时在nginx.conf配置文件更改user指令。
	默认的用户名是nobody。--group=name类似
--with-pcre : 
	设置PCRE库的源码路径,如果已通过yum方式安装,
	使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,
	需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,
	剩下的就交给Nginx的./configure和make来完成。
	perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
--with-zlib=PATH : 
	指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。
	在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
--with-http_ssl_module : 
	使用https协议模块。默认情况下,该模块没有被构建。
	前提是openssl与openssl-devel已安装
--with-http_stub_status_module : 
	用来监控 Nginx 的当前状态
--with-http_realip_module : 
	通过这个模块允许我们改变客户端请求头中客户端IP地址值
	(例如X-Real-IP 或 X-Forwarded-For),
	意义在于能够使得后台服务器记录原始客户端的IP地址
--add-module=PATH : 
	添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。
	每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)

5、编辑配置文件

[root@140106 nginx-1.15.10]# cd /usr/local/nginx/
[root@140106 nginx]# vim conf/nginx.conf

6、启动停止和重启

// 指定配置文件启动
[root@140106 nginx]# ./sbin/nginx -c conf/nginx.conf

// 启动后查看进程
[root@140106 nginx]# ps -ef|grep nginx
root     30533     1  0 16:11 ?        00:00:00 nginx: master process ./sbin/nginx -c conf/nginx.conf
nobody   30534 30533  0 16:11 ?        00:00:00 nginx: worker process
root     30542 27715  0 16:32 pts/0    00:00:00 grep --color=auto nginx

// 修改配置文件后重启
[root@140106 nginx]# ./sbin/nginx -s reload

// 停止服务
[root@140106 nginx]# ./sbin/nginx -s stop

7、结束

愉快的玩耍去吧

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值