如何在 ubuntu18.04安装nginx ?
参考官方文档:http://nginx.org/en/linux_packages.html#Ubuntu
稳定版安装示例:
- Install the prerequisites(安装必备组件):
sudo apt install curl gnupg2 ca-certificates lsb-release
- To set up the apt repository for stable nginx packages, run the following command(要为稳定的nginx包设置apt存储库,请运行以下命令):
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
- Next, import an official nginx signing key so apt could verify the packages authenticity(接下来,导入一个官方nginx签名密钥,以便apt能够验证包的真实性):
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
- Verify that you now have the proper key(确认您现在有正确的钥匙):
sudo apt-key fingerprint ABF5BD827BD9BF62
- The output should contain the full fingerprint
573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
as follows(输出应包含完整指纹573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62,如下所示):pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 uid [ unknown] nginx signing key <signing-key@nginx.com>
- To install nginx, run the following commands(要安装nginx,请运行以下命令):
sudo apt update sudo apt install nginx
到这里就已经安装成功了。
- 启动nginx
sudo /etc/init.d/nginx start
- 查看nginx状态
sudo /etc/init.d/nginx status
- 更多用法
每当修改了nginx配置文件后,先执行sudo /etc/init.d/nginx configtest
再执行
sudo /etc/init.d/nginx check-reload
- 测试
curl -I localhost
发表回复