centos7安装nginx并自启
虽然都是linux,但是安装的依赖包有点差别。
sudo apt install build-essential
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl libssl-dev
cd nginx-1.18.0/
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make & make install
Ubuntu 16.10开始不再使用initd管理系统,改用systemd,包括用systemctl命令来替换了service和chkconfig的功能。
比如以前启动mysql服务用sudo service mysql start,现在用sudo systemctl start mysqld.service。
systemd 默认读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
WorkingDirectory=/usr/local/nginx
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
systemctl status nginx
联系客服