Nginx Linux下安装部署

1、安装包准备

  1. pcre-8.44.tar.gz
  2. nginx-1.18.0.tar.gz

上传至服务器/root/package 目录

tar -zxf pcre-8.44.tar.gz
tar -zxf nginx-1.18.0.tar.gz

2、基础环境准备

        安装依赖包

yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel  make

3、编译

pcre编译

cd pcre-8.44
 ./configure --prefix=/usr/local/pcre
make && make install

nginx编译

cd nginx-1.18.0/
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.44
make && make install

4、启动测试

cd /usr/local/nginx/
sbin/nginx
 ps -fe | grep nginx
输出:
root       54121       1  0 10:14 ?        00:00:00 nginx: master process sbin/nginx
nobody     54122   54121  0 10:14 ?        00:00:00 nginx: worker process
root       54124   30826  0 10:15 pts/1    00:00:00 grep --color=auto nginx

5、Nginx 设置开机自启

新建 /usr/lib/systemd/system/nginx.service 文件

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改nginx.conf pid配置 和用户

user  root;
# pid文件生成位置与nginx.service 保持一致
pid        /var/run/nginx.pid;

启动nginx 并检查状态

#启动nginx服务
systemctl  start  nginx.service
systemctl  status  nginx.service
#输出
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-07-04 11:22:48 CST; 4min 18s ago
 Main PID: 55135 (nginx)
    Tasks: 3 (limit: 101361)
   Memory: 3.4M
   CGroup: /system.slice/nginx.service
           ├─55135 nginx: master process /usr/local/nginx/sbin/nginx
           ├─55136 nginx: worker process
           └─55137 nginx: worker process

Jul 04 11:22:48 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jul 04 11:22:48 localhost.localdomain nginx[55132]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Jul 04 11:22:48 localhost.localdomain nginx[55132]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Jul 04 11:22:48 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.

设置开机自启

 systemctl  enable  nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值