本博主要示例通过编译nginx官网的源码的方式,安装nginx程序包。
如果想通过yum方式安装nginx,可查看官方文档 http://nginx.org/en/linux_packages.html
系统环境
linux内核版本 3.10.0-514.el7.x86_64
centos系统版本 CentOS Linux release 7.3.1611 (Core)
IP地址 172.16.55.7/16 192.168.55.135/24
准备
关闭selinux,清空iptables规则(对这些熟悉的同学可以不做处理)
1.下载nginx源码
~]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
2.安装nginx依赖的程序包
~]# yum install -y pcre-devel openssl-devel zlib-devel
3.创建nginx系统用户
~]# useradd -r -s /sbin/nologin nginx
4.解压nginx源码包
~]# tar xvf nginx-1.10.3.tar.gz
5.根据具体需求编译源码
nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --sbin-path=/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio
nginx-1.10.3]# make && make install
6.启动nginx服务
[root@localhost nginx]# nginx # 启动nginx[root@localhost nginx]# ps aux | grep nginxroot 13324 0.0 0.0 45428 1116 ? Ss 09:52 0:00 nginx: master process nginxnginx 13325 0.0 0.0 47964 1956 ? S 09:52 0:00 nginx: worker processroot 13336 0.0 0.0 112648 960 pts/3 R+ 09:52 0:00 grep --color=auto nginx [root@localhost nginx]# ss -tnlp | grep nginx # 监听80端口 LISTEN 0 128 *:80 *:* users:(("nginx",pid=13325,fd=6),("nginx",pid=13324,fd=6))
7.访问nginx服务
[root@localhost nginx]# curl 172.16.55.7Welcome to nginx! Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.
Commercial support is available atnginx.com.Thank you for using nginx.