1、下载相关安装包
https://nginx.org/en/download.html
也可以提前下载好然后上传到服务器上
2、解压
tar -zxvf nginx-1.26.0.tar.gz
3、查看是否安装过gcc
3.1查看gcc版本
[root@localhost local]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
3.2 没有安装的执行
[root@localhost local]# yum install gcc-c++
4、指定安装路径
[root@ecs-x64y90008 src]# cd nginx-1.26.0/
[root@ecs-x64y90008 nginx-1.26.0]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid
--prefix= 这个关键字的作用是编译的时候用于指定程序存放的路径
--sbin-path=指定sbin路径
--conf-path=指定conf文件路径
--pid-path=指定pid文件路径
后面三个可以不用设置 (看个人需求)
5、编译
[root@ecs-x64y90008 src]# make && make install
6、启动
[root@ecs-x64y90008 local]# cd /usr/local/nginx
[root@ecs-x64y90008 nginx]# ./nginx
7、查看是否启动成功
[root@ecs-x64y90008 nginx]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3279 0.0.0.0:* LISTEN 64343/dropbear
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 269164/nginx: maste
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 114271/sshd: /usr/s
tcp6 0 0 :::3279 :::* LISTEN 64343/dropbear
tcp6 0 0 :::22 :::* LISTEN 114271/sshd: /usr/s
[root@ecs-x64y90008 nginx]#