ubuntu 18.04 安装 nginx

ubuntu 18.04 安装 nginx

服务器上安装了两个服务。通过外网加端口访问。需求通过nginx代理访问两个服务。操作记录备忘。

环境

ubuntu 18.04,非root,常规用户账户。

Step1-Installing Nginx

Ubuntu 18.04默认软件库中包含Nginx包。所以可以直接通过apt包管理工具进行安装。

1
2
sudo apt update
sudo apt install nginx

Step2-Adjusting the Firewall

在进行Nginx测试之前,需求调整防火墙设置放通Nginx服务。

相看ufw应用列表。

1
sudo ufw app list

输出内容:

Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS

如所见,Nginx Full即放通80和443,Nginx HTTP即放通80,Nginx HTTPS即放通443。

1
sudo ufw allow 'Nginx FULL'

Step3-Checking your Web Server

安装结束,程序服务就会启用。通过systemctl查看Nginx相关的进程信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo systemctl status nginx 

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-04-13 09:41:04 UTC; 10s ago
Docs: man:nginx(8)
Process: 4576 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
Process: 4586 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 4577 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 4589 (nginx)
Tasks: 2 (limit: 1110)
CGroup: /system.slice/nginx.service
├─4589 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─4593 nginx: worker process

Apr 13 09:41:04 vultr_vps_server systemd[1]: Starting A high performance web server and a reverse proxy server...

安装程序结束。

一个小问题:启动后的nginx有一个状态问题:

nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument

解决方法:

1
2
3
4
5
Workaround:

mkdir /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload

ubuntu 18.04 安装 nginx
https://ywmy.xyz/2019/04/12/ubuntu-18-04-安装-nginx/
作者
ian
发布于
2019年4月12日
许可协议