Nginx-1.22.0部署方案

蜜獾互联网發表於2024-12-09

準備工作

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

相關文章