1.18.0 nignx 部署

安装依赖

 yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

解压

 tar xf nginx-1.18.0.tar.gz -C /data/

创建虚拟用户

useradd www -s /sbin/nologin/ -M

编译

./configure --prefix=/data/nginx-1.18.0 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module

安装

make && make install

软链接

ln  -s /data/nginx-1.18.0 /data/nginx

精简nginx 配置

grep -Ev "#|^$" nginx.conf.default >nginx.conf

添加环境变量

vi  /etc/profile

最后一行

PATH=$PATH:/data/nginx/bin/:/data/nginx/sbin

加载环境变量

source /etc/profile

添加system 启动方式

cat <<EOF> /usr/lib/systemd/system/nginx.service 
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
#EnvironmentFile=/etc/sysconfig/rdisc
#ExecStart=/sbin/rdisc $RDISCOPTS

[Install]
WantedBy=multi-user.target
EOF

加载 启动方式

systemctl daemon-reload 

配置虚拟主机

vim /data/nginx/conf/nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  data/octet-stream;
    sendfile           on;
    server_tokens      off;
    keepalive_timeout  65;
    server {
            listen       80;
            server_name  ;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
            }
        }
}

启动命令

systemctl restart nginx

停止命令

systemctl stop nginx

重启命令

systemctl restart nginx
posted @ 2021-03-11 17:05  名字长的像一只老山羊  阅读(79)  评论(0编辑  收藏  举报