OS: Ubuntu
引用
安装
$ sudo apt update
$ sudo apt install nginx
防火墙
$ sudo ufw app list
Output
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw status
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
检查状态
$ systemctl status nginx
$ sudo systemctl stop nginx
$ sudo systemctl start nginx
$ sudo systemctl restart nginx
$ sudo systemctl reload nginx
$ sudo systemctl disable nginx
设置服务访问目录
/var/www/html # 默认目录
$ sudo mkdir -p /var/www/example.com/html
$ sudo chown -R $USER:$USER /var/www/example.com/html
$ sudo chmod -R 755 /var/www/example.com
$ nano /var/www/example.com/html/index.html
<html>
<head>
<title>Welcome to Example.com!</title>
</head>
<body>
<h1>Success! The example.com server block is working!</h1>
</body>
</html>
$ sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
$ sudo nano /etc/nginx/nginx.conf
...
http {
...
server_names_hash_bucket_size 64;
...
}
...
$ sudo nginx -t
Nginx 文件目录
内容
- /var/www/html
服务配置
- /etc/nginx
- /etc/nginx/nginx.conf
- /etc/nginx/sites-available/
- /etc/nginx/sites-enabled/
- /etc/nginx/snippets
日志
- /var/log/nginx/access.log
- /var/log/nginx/error.log
网友评论