源码编译Nginx

1.Nginx适用环境:

实现网站服务 web

反向代理服务器 

​          可以为web服务器做代理

          或者是mail服务器做代理(很少)

特点:

1、隐藏后端地址

2、缓存、可以加快客户端的访问速度

3、负载均衡

4、承载大并发

2.Nginx安装

nginx下载地址
http://nginx.org/

https://www.nginx.cn/

https://www.nginx.cn/doc/

安装前准备:


[root@nginx ~]# useradd nginx  #不创建的话默认用户nobody

[root@nginx ~]# mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
#client : 存客户端文件
#proxy:代理文件
#fastcgi:cgi是通用网关协议,不高效,fastcgi是一种常驻型CGI服务,
#uwsgi:以下两种类似于fastcgi,不同的传输协议而已
#scgi:

[root@localhost ~]# yum install -y gcc-c++ pcre-devel openssl openssl-devel zlib-devel  #依赖环境

[root@nginx ~]# tar zxf nginx-1.20.0.tar.gz 
[root@nginx ~]# cd nginx-1.20.0/
[root@nginx nginx-1.11.4]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre \
--with-file-aio \
--with-http_secure_link_module \
--with-threads \

make && make install 


如果需要删除源码包,直接删除安装目录即可。 
[root@localhost ~]# rm -rf /usr/local/nginx/

3.nginx目录介绍

	/usr/local/nginx/conf     nginx.conf	配置文件

​	/usr/local/nginx/html	  默认网页目录

​	/usr/local/nginx/logs	  日志(启动后产生)

​	/usr/local/nginx/sbin	  nginx二进制程序(启动关闭、配置文件读取、语法检查等功能)

启动nginx

[root@nginx ~]# /usr/local/nginx/sbin/nginx 

[root@nginx ~]# ss -antp | grep nginx

LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=7691,fd=6),("nginx",pid=7690,fd=6))

[root@nginx ~]# ps aux | grep nginx

root      7690  0.0  0.1  47552  1116 ?        Ss   11:20   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nginx     7691  0.0  0.2  50076  2220 ?        S    11:20   0:00 nginx: worker process

root      7708  0.0  0.0 112660   932 pts/0    S+   11:21   0:00 grep --color=auto nginx

4.设置开机自启nginx

[root@nginx ~]# tail -1 /etc/rc.d/rc.local

/usr/local/nginx/sbin/nginx

[root@nginx ~]# chmod a+x /etc/rc.d/rc.local

5.nginx常用命令

mkdir /root/bin

ln -s /usr/local/nginx/sbin/nginx /root/bin/nginx

做完以上步骤后,可以在任意路径下使用nginx命令

常用选项:

nginx -t 

nginx 

nginx -s reload	

nginx -s stop

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进一步。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值