参考链接

开始安装

当前,使用的是 Ubuntu 16.04

更新包列表

1
sudo apt update

安装 Nginx

1
sudo apt install nginx

安装 MySQL

1
2
sudo apt install mysql-server
sudo mysql_secure_installation

安装 PHP 及 MySQL 扩展

1
sudo apt install php-fpm php-mysql

修改 PHP 配置并重启

1
2
3
4
5
sudo vi /etc/php/7.0/fpm/php.ini
#################
## 取消 cgi.fix_pathinfo 的注释并修改其值
cgi.fix_pathinfo=0
#################
1
sudo systemctl restart php7.0-fpm

创建访问目录,更新 Nginx 配置并重启

1
2
3
sudo mkdir /var/www/test-pages/
sudo chown $(whoami):$(whoami) /var/www/test-pages/
echo "Hello Nginx" > /var/www/test-pages/index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
sudo vi /etc/nginx/sites-available/default
#################
server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;
index index.php index.html index.htm;

server_name _;
location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}
#################
1
sudo systemctl reload nginx

尝试访问

1
http://YOUR-IP-ADDRESS/


更多配置

指定域名访问

HTTPS 证书配置