linux之nginx安装部署

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux之nginx安装部署相关的知识,希望对你有一定的参考价值。


[[email protected] ~]# mkdir /home/oldboy/tools -p          #创建安装包存放位置

[[email protected] ~]# cd /home/oldboy/tools/

[[email protected] tools]# rz -y             #上传nginx安装包

[[email protected] tools]# #wget -q http://nginx.org/download/nginx-1.10.2.tar.gz          #如果没有安装包可执行wget下载

[[email protected] tools]# ls

nginx-1.8.1.tar.gz

[[email protected] tools]# tar xf nginx-1.8.1.tar.gz            #解压上传的安装包

[[email protected] tools]# useradd -s /sbin/nologin -M www     #创建nginx服务对应的用户,这里为www  不建立家目录

[[email protected] tools]# id www      #操作后检查
uid=501(www) gid=501(www) 组=501(www)

[[email protected] tools]# yum install pcre-devel pcre openssl-devel openssl -y      #yum下载nginx所需要的依赖包
已加载插件:fastestmirror, security
设置安装进程
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                       | 3.7 kB     00:00     
epel                                                                       | 4.3 kB     00:00     
epel/primary_db                                                            | 5.9 MB     00:10     
extras                                                                     | 3.4 kB     00:00     
updates                                                                    | 3.4 kB     00:00     
updates/primary_db                                                         | 5.4 MB     00:08     
包 pcre-7.8-7.el6.x86_64 已安装并且是最新版本
解决依赖关系
--> 执行事务检查
---> Package openssl.x86_64 0:1.0.1e-48.el6 will be 升级
---> Package openssl.x86_64 0:1.0.1e-48.el6_8.4 will be an update

…………

作为依赖被安装:
  keyutils-libs-devel.x86_64 0:1.4-5.el6           krb5-devel.x86_64 0:1.10.3-57.el6             
  libcom_err-devel.x86_64 0:1.41.12-22.el6         libselinux-devel.x86_64 0:2.0.94-7.el6        
  libsepol-devel.x86_64 0:2.0.41-4.el6             zlib-devel.x86_64 0:1.2.3-29.el6              

更新完毕:
  openssl.x86_64 0:1.0.1e-48.el6_8.4                                                              

完毕!


[[email protected] tools]# cd nginx-1.8.1
[[email protected] nginx-1.8.1]# ./configure --user=www --group=www --prefix=/application/nginx-1.8.1/ --with-http_stub_status_module --with-http_ssl_module        #生成 Makefile,为下一步的编译做准备

checking for OS
 + Linux 2.6.32-642.el6.x86_64 x86_64
checking for C compiler ... found
…………

  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"


[[email protected] nginx-1.8.1]#  make       #编译
make -f objs/Makefile
make[1]: Entering directory `/home/oldboy/tools/nginx-1.8.1‘
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
…………

        -e "s|%%PID_PATH%%|/application/nginx-1.8.1//logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/application/nginx-1.8.1//conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/application/nginx-1.8.1//logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/oldboy/tools/nginx-1.8.1‘

[[email protected] nginx-1.8.1]#  make install       #安装
make -f objs/Makefile install
make[1]: Entering directory `/home/oldboy/tools/nginx-1.8.1‘
test -d ‘/application/nginx-1.8.1/‘ || mkdir -p ‘/application/nginx-1.8.1/‘
…………
test -d ‘/application/nginx-1.8.1//html‘         || cp -R html ‘/application/nginx-1.8.1/‘
test -d ‘/application/nginx-1.8.1//logs‘ ||         mkdir -p ‘/application/nginx-1.8.1//logs‘
make[1]: Leaving directory `/home/oldboy/tools/nginx-1.8.1‘


[[email protected] nginx-1.8.1]# ln -s /application/nginx-1.8.1/ /application/nginx       #为nginx创建软连接  
[[email protected] nginx-1.8.1]# ll /application/
总用量 4
lrwxrwxrwx 1 root root   25 3月   7 22:51 nginx -> /application/nginx-1.8.1/
drwxr-xr-x 6 root root 4096 3月   7 22:43 nginx-1.8.1

[[email protected] nginx-1.8.1]# /application/nginx/sbin/nginx -t           #操作后检查语法、规范
nginx: the configuration file /application/nginx-1.8.1//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.1//conf/nginx.conf test is successful

[[email protected] nginx-1.8.1]# /application/nginx/sbin/nginx           #启动nginx服务

[[email protected] nginx-1.8.1]# lsof -i:80              #查看服务是否正常开启
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   4154 root    6u  IPv4  15963      0t0  TCP *:http (LISTEN)
nginx   4155  www    6u  IPv4  15963      0t0  TCP *:http (LISTEN)



  • 通过浏览器查看结果.输入服务器IP


技术分享

到这一步nginx就安装完毕了!



  • 通过命令堆积一个简单的安装nginx脚本


[[email protected] ~]# cat /server/scripts/nginx_install.sh

#!/bin/bash

. /etc/profile


mkdir /home/oldboy/tools -p

cd /home/oldboy/tools/

wget -q http://nginx.org/download/nginx-1.8.1.tar.gz

tar xf nginx-1.8.1.tar.gz

useradd -s /sbin/nologin -M www

cd nginx-1.8.1

yum install pcre-devel pcre openssl-devel openssl -y


 ./configure --user=www --group=www --prefix=/application/nginx-1.8.1/ --with-http_stub_status_module --with-http_ssl_module

make && make install 

ln -s /application/nginx-1.8.1/ /application/nginx

/application/nginx/sbin/nginx










本文出自 “lming” 博客,请务必保留此出处http://lmin32.blog.51cto.com/12206256/1904142

以上是关于linux之nginx安装部署的主要内容,如果未能解决你的问题,请参考以下文章

Nginx Linux详细安装及部署实战

Linux 6.5 部署LNMP之Nginx 服务

Linux基础运维安装部署nginx

Linux安装部署Nginx

Linux安装部署Nginx

nginx安装与调优部署文档(Linux)