web服务之nginx(安装)

Nginx安装方式

.源码安装
1.下载nginx源码包 http://nginx.org/download/获取地址
这里以nginx-1.14.0.tar.gz演示
下载nginx-1.14.02.创建安装目录,准备安装环境
[root@localhost ~]# mkdir -p /opt/data/nginx/
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx nginx
3.安装依赖包
[root@localhost ~]# yum install gcc gcc-c++ make recp pcre-devel openssl openssl-devel -y
4.解压
[root@localhost ~]# tar -xf nginx-1.14.0.tar.gz -C /usr/local/src/
/usr/local/src/ 为解压目录切勿与安装目录混淆
5.编译安装
[root@localhost ~]# cd /usr/local/src/nginx-1.14.0/
[root@localhost nginx-1.14.0]# ./configure --prefix=/opt/data/nginx --with-http_stub_stat us_module --with-http_ssl_module --with-stream

[root@localhost nginx-1.14.0]# make & make install
6.配置环境变量
[root@localhost ~]# vim /etc/profile
在这里插入图片描述[root@localhost ~]# source /etc/profile
7.nginx配置
[root@localhost ~]# ln -s /opt/data/nginx/conf /etc/nginx
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# mv nginx.conf nginx.conf.bak
[root@localhost nginx]# vim nginx.conf
user nginx;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log off;
client_max_body_size 128M;
include /etc/nginx/conf.d/*.conf;
}

[root@localhost nginx]# mkdir /etc/nginx/conf.d
[root@localhost nginx]# mkdir /var/log/nginx
[root@localhost nginx]# chown -R nginx:nginx /var/log/nginx
8.nginx启动

[root@localhost nginx]# vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/opt/data/nginx/sbin/nginx -t -c /opt/data/nginx/conf/nginx.conf
ExecStart=/opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
ExecStartPost=/bin/sleep 0.1
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]# systemctl enable nginx
[root@localhost nginx]# systemctl status nginx
启动成功
此时nginx进程已经启动 但是没有nginx实例没有80端口。

遇见问题
首次启动

Failed to read PID from file /var/run/nginx.pid: Invalid argument
问题解决办法:vim /lib/systemd/system/nginx.service
在这里插入图片描述加入图上箭头上的内容解决
[root@localhost nginx]# systemctl daemon-reload
[root@localhost nginx]# systemctl restart nginx.service
[root@localhost nginx]# systemctl status nginx
问题解决因为 nginx 启动需要一点点时间,而 systemd 在 nginx 完成启动前就去读取 pid file
造成读取 pid 失败
让 systemd 在执行 ExecStart 的指令后等待一点点时间即可
如果你的 nginx 启动需要时间更长,可以把 sleep 时间改长一点

参考资料:参考链接

、yum安装方式

yum安装请参考这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值