Nginx-1.22.0部署方案

准备工作

1、创建用户和配置环境参数

(1)、创建用户和创建所需目录

[root@nginx ~]# groupadd nginx
[root@nginx ~]# useradd -d /home/nginx -g nginx -m nginx
[root@nginx ~]# chmod 755 /home/nginx
[root@nginx ~]# mkdir -p /home/nginx/software
[root@nginx ~]# mkdir -p /home/nginx/yunwei
[root@nginx ~]# chown -R nginx:nginx /home/nginx
[root@nginx ~]# mkdir -p /data/nginx
[root@nginx ~]# chown -R nginx:nginx /data/nginx

2、下载

https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/z...
https://www.openssl.org/source/openssl-1.1.1h.tar.gz
https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
http://nginx.org/download/nginx-1.22.0.tar.gz
https://codeload.github.com/vozlt/nginx-module-vts/tar.gz/v0.1.18

3、部署

(1)、解压安装包并备份配置文件

[nginx@nginx ~]$ tar -zxvf $HOME/software/zlib-1.2.11.tar.gz -C $HOME/software/
[nginx@nginx ~]$ tar -zxvf $HOME/software/openssl-1.1.1h.tar.gz -C $HOME/software/
[nginx@nginx ~]$ tar -zxvf $HOME/software/pcre-8.44.tar.gz -C $HOME/software/
[nginx@nginx ~]$ tar -zxvf $HOME/software/nginx-1.22.0.tar.gz -C $HOME/software/
[nginx@nginx ~]$ tar -zxvf $HOME/software/nginx-module-vts-0.1.18.tar.gz -C $HOME/software/
[nginx@nginx ~]$ cd $HOME/software/nginx-1.22.0
[nginx@nginx software/nginx-1.22.0]$ ./configure --prefix=$HOME/nginx-1.22.0 --with-http_ssl_module --with-pcre=$HOME/software/pcre-8.44 --with-zlib=$HOME/software/zlib-1.2.11 --with-openssl=$HOME/software/openssl-1.1.1h --with-http_stub_status_module --add-module=$HOME/software/nginx-module-vts-0.1.18
[nginx@nginx software/nginx-1.22.0]$ make
[nginx@nginx software/nginx-1.22.0]$ make install
[nginx@nginx software/nginx-1.22.0]$ cp $HOME/nginx-1.22.0/conf/nginx.conf $HOME/nginx-1.22.0/conf/nginx.conf_init

(2)、创建所需目录

[nginx@nginx ~]$ mkdir -p /data/nginx/nginx-1.22.0/logs
[nginx@nginx ~]$ mkdir -p $HOME/nginx-1.22.0/conf/conf.d
[nginx@nginx ~]$ mkdir -p $HOME/nginx-1.22.0/html/operation_workspaces

4、调整配置文件

(1)、根据实际情况调整nginx.conf配置文件

[nginx@nginx ~]$ vi $HOME/nginx-1.22.0/conf/nginx.conf
#user  nobody;
worker_processes  2;

#error_log  logs/error.log;
error_log  /data/nginx/nginx-1.22.0/logs/error.log warn;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
pid /data/nginx/nginx-1.22.0/logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    
    vhost_traffic_status_zone;
    vhost_traffic_status_filter_by_host on;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $request_time';

    #access_log  logs/access.log  main;
    access_log  /data/nginx/nginx-1.22.0/logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # 导入子配置文件,这里引用*,表示所有的.conf文件都会被调用
    include conf.d/*.conf;

}

(2)、根据实际情况调整default.conf子配置文件

[nginx@nginx ~]$ vi $HOME/nginx-1.22.0/conf/conf.d/default.conf
server {
    listen       8000;
    server_name  localhost;
    charset utf-8;

    #charset koi8-r;
    access_log  /data/nginx/nginx-1.22.0/logs/default.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location /status {
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

5、起停服务与创建对应脚本

(1)、 创建启动服务脚本

[nginx@nginx ~]$ vi $HOME/yunwei/nginx-1.22.0_start.sh
#!/bin/bash

cd $HOME/nginx-1.22.0/sbin
 ./nginx -c $HOME/nginx-1.22.0/conf/nginx.conf

(2)、 创建停止服务脚本

[nginx@nginx ~]$ vi $HOME/yunwei/nginx-1.22.0_stop.sh
#!/bin/bash

cd $HOME/nginx-1.22.0/
./sbin/nginx -s stop

(3)、 创建平滑重起服务脚本

[nginx@nginx ~]$ vi $HOME/yunwei/nginx-1.22.0_reload.sh
#!/bin/bash

cd $HOME/nginx-1.22.0/
./sbin/nginx -s reload

你可能感兴趣的:(nginxlinux运维)