nginx安装,运行(ubuntu)

文本只涉及单节点nginx

 

安装gcc g++依赖库

apt-get install build-essential
apt-get install libtool

 

安装pcre依赖库

apt-get update
apt-get install libpcre3 libpcre3-dev

 

安装zlib依赖库

apt-get install zlib1g-dev

 

安装ssl依赖库

apt-get install openssl

 

下载并安装

wget -P /opt/downloads http://nginx.org/download/nginx-1.15.9.tar.gz
tar zxvf /opt/downloads/nginx-1.15.9.tar.gz -C /opt
cd /opt/nginx-1.15.9
./configure
./configure --prefix=/opt/nginx make make install

 

修改nginx配置

vim /usr/local/nginx/conf/nginx.conf

放出pid

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;

 去掉http节点下某些注释(非必须)

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

    access_log  logs/access.log  main;

 

验证配置文件

/usr/local/nginx/sbin/nginx -t 

启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

注:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。

停止

/usr/local/nginx/sbin/nginx -s stop

帮助

/usr/local/nginx/sbin/nginx -h

 

 

守护进程启动:

vim /lib/systemd/system/nginx.service

 

[Unit]
Description=nginx
After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type
=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=
/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload -c /usr/local/nginx/conf/nginx.conf
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

 

赋予权限

chmod 777 /lib/systemd/system/nginx.service

 

启用守护进程

systemctl enable nginx.service
systemctl daemon-reload

 

运行

systemctl start nginx.service

查看日志 

journalctl -f -u nginx.service

查看状态

systemctl status nginx.service

 

查看nginx进程

ps -ef|grep nginx

 

转载于:https://www.cnblogs.com/wintersoft/p/10537946.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值