0
点赞
收藏
分享

微信扫一扫

linux下nginx部署

官网:nginx官网

源码包:nginx-1.16.1.tar.gz

1、源码包下载

wget http://nginx.org/download/nginx-1.16.1.tar.gz

已经下载到Linux系统里面

[root@centos ~]# ls
anaconda-ks.cfg  install  nginx-1.16.1.tar.gz

2、解压

[root@centos ~]# tar xvf nginx-1.16.1.tar.gz  -C /usr/local/src/
nginx-1.16.1/
nginx-1.16.1/auto/
nginx-1.16.1/conf/
nginx-1.16.1/contrib/
nginx-1.16.1/src/
nginx-1.16.1/configure
nginx-1.16.1/LICENSE
nginx-1.16.1/README
nginx-1.16.1/html/
nginx-1.16.1/man/
nginx-1.16.1/CHANGES.ru
nginx-1.16.1/CHANGES
nginx-1.16.1/man/nginx.8
nginx-1.16.1/html/50x.html
nginx-1.16.1/html/index.html
nginx-1.16.1/src/core/
nginx-1.16.1/src/event/
nginx-1.16.1/src/http/
nginx-1.16.1/src/mail/
nginx-1.16.1/src/misc/
nginx-1.16.1/src/os/
...........................................

3、安装相应的开发工具

[root@centos ~]# yum groupinstall "Development tools"
[root@centos ~]# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel

4、进入nginx目录对应的目录进行编译安装

1、进入对应目录
[root@centos ~]# cd /usr/local/src/nginx-1.16.1
2、执行以下命令
[root@centos nginx-1.16.1]# ./configure \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/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 \
> --http-client-body-temp-path=/var/tmp/nginx/client \
> --http-proxy-temp-path=/var/tmp/nginx/proxy \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
> --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> --http-scgi-temp-path=/var/tmp/nginx/scgi \
> --user=nginx \
> --group=nginx \
> --with-pcre \
> --with-http_v2_module \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_addition_module \
> --with-http_sub_module \
> --with-http_dav_module \
> --with-http_flv_module \
> --with-http_mp4_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_random_index_module \
> --with-http_secure_link_module \
> --with-http_stub_status_module \
> --with-http_auth_request_module \
> --with-mail \
> --with-mail_ssl_module \
> --with-file-aio \
> --with-ipv6 \
> --with-http_v2_module \
> --with-threads \
> --with-stream \
> --with-stream_ssl_module

linux下nginx部署_centos

至此:已经完成了编译安装

1、编译内核或源码文件
[root@centos nginx-1.16.1]# make && make install
2、创建目录
[root@centos nginx-1.16.1]# mkdir -pv /var/tmp/nginx/client

5、添加SysV启动脚本

1、创建脚本文件并编写脚本
[root@centos nginx-1.16.1]# vi /etc/init.d/nginx
#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemon 
# 
# chkconfig:   - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#               proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 
# Source function library. 
. /etc/rc.d/init.d/functions
# Source networking configuration. 
. /etc/sysconfig/network
# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo 
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT
    retval=$?
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
killall -9 nginx
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP
RETVAL=$?
    echo 
}
force_reload() {
    restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
    $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
      echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2
esac

6、赋予脚本执行权限

1、赋权
[root@centos nginx-1.16.1]# chmod +x /etc/init.d/nginx
2、添加nginx服务进程用户
[root@centos nginx-1.16.1]# groupadd -r nginx
[root@centos nginx-1.16.1]# useradd -r -g nginx nginx
3、添加至服务管理列表,设置开机自启
[root@centos nginx-1.16.1]# chkconfig --add nginx
[root@centos nginx-1.16.1]# chkconfig nginx on

7、关闭防火墙并启动nginx

1、关闭防火墙
[root@centos nginx-1.16.1]# systemctl stop firewalld
2、启动nginx
[root@centos nginx-1.16.1]# service nginx start
Starting nginx (via systemctl):                            [  OK  ]

8、查看本机IP地址

[root@centos nginx-1.16.1]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default q                                                                len 1000
    link/ether 00:0c:29:5d:09:4f brd ff:ff:ff:ff:ff:ff
    inet 172.16.200.145/24 brd 172.16.200.255 scope global noprefixroute dynamic ens33
       valid_lft 1413sec preferred_lft 1413sec
    inet6 fe80::6e8a:4ad9:98e0:f63f/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

由ip a或者ifconfig可以查看IP地址

使用http://172.16.200.145/查看nginx默认测试界面

linux下nginx部署_html_02

附:nginx常用目录

nginx path prefix: “/usr/local/nginx”

nginx binary file: “/usr/local/nginx/sbin/nginx”

nginx modules path: “/usr/local/nginx/modules”

nginx configuration prefix: “/usr/local/nginx/conf”

nginx configuration file: “/usr/local/nginx/conf/nginx.conf”

nginx pid file: “/usr/local/nginx/logs/nginx.pid”

nginx error log file: “/usr/local/nginx/logs/error.log”

nginx http access log file: “/usr/local/nginx/logs/access.log”

附:nginx详细配置

配置选项

说明

--prefix

nginx的安装目录,默认为/usr/local/nginx

--sbin-path

nginx可执行文件路径,若没有设置则依赖于--prefix

--conf-path

设置nginx.conf配置文件路径,nginx启动时可以通过-c参数指定配置文件

--error-log-path

错误日志路径

--http-log-path

http主请求日志文件

--pid-path

存放nginx进程的pid号

--lock-path

共享存储器互斥锁文件路径


举报

相关推荐

0 条评论