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

 

posted @ 2019-03-15 16:32  wintersoft  阅读(285)  评论(0编辑  收藏  举报