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 --prefix=/opt/nginx
make
make install

验证配置文件

/opt/nginx/sbin/nginx -t 

启动

/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

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

停止

/opt/nginx/sbin/nginx -s stop

帮助

/opt/nginx/sbin/nginx -h

守护进程启动:

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx

[Service]
Type=forking
User=root
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload -c /opt/nginx/conf/nginx.conf
ExecStop=/opt/nginx/sbin/nginx -s stop
Restart=always
PrivateTmp=true
WorkingDirectory=/

[Install]
WantedBy=multi-user.target

赋予权限

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

启用守护进程

systemctl enable nginx.service
systemctl daemon-reload

运行

systemctl start nginx.service

查看状态

systemctl status nginx.service

查看nginx进程

ps -ef|grep nginx

猜你喜欢

转载自www.cnblogs.com/wintersoft/p/10537946.html
今日推荐