一. 安装步骤
1. apt update
2. apt install nginx
3. ufw app list
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
4.ufw allow 'Nginx HTTP'
5. systemctl status nginx
二. 路径:
配置:
root@ubuntu:/etc/nginx# ll
total 64
drwxr-xr-x 6 root root 4096 Aug 8 23:09 ./
drwxr-xr-x 102 root root 4096 Aug 8 16:26 ../
drwxr-xr-x 2 root root 4096 Nov 7 2018 conf.d/
-rw-r--r-- 1 root root 1077 Feb 12 2017 fastcgi.conf
-rw-r--r-- 1 root root 1007 Feb 12 2017 fastcgi_params
-rw-r--r-- 1 root root 2837 Feb 12 2017 koi-utf
-rw-r--r-- 1 root root 2223 Feb 12 2017 koi-win
-rw-r--r-- 1 root root 3957 Feb 12 2017 mime.types
-rw-r--r-- 1 root root 1462 Feb 12 2017 nginx.conf
-rw-r--r-- 1 root root 180 Feb 12 2017 proxy_params
-rw-r--r-- 1 root root 636 Feb 12 2017 scgi_params
drwxr-xr-x 2 root root 4096 Aug 9 09:31 sites-available/
drwxr-xr-x 2 root root 4096 Aug 8 23:11 sites-enabled/
drwxr-xr-x 2 root root 4096 Aug 8 16:26 snippets/
-rw-r--r-- 1 root root 664 Feb 12 2017 uwsgi_params
-rw-r--r-- 1 root root 3071 Feb 12 2017 win-utf
静态资源:
root@ubuntu:/var/www/html# ll
total 12
drwxr-xr-x 2 root root 4096 Aug 9 12:26 ./
drwxr-xr-x 4 root root 4096 Aug 8 17:00 ../
-rw-r--r-- 1 root root 645 Aug 9 12:26 index.nginx-debian.html
三. 命令:
启动: systemctl restart nginx
修改配置: nginx -s reload
四. 转发请求到Tomcat
vi /etc/nginx/sites-enabled/default
修改配置成:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:8080;
# try_files $uri $uri/ =404;
}
8080为tomcat 服务端口号
五. Server 配置
root@ubuntu:/etc/nginx/sites-available# cat test.com
server {
listen 9999;
listen [::]:9999;
location / {
proxy_pass https://www.baidu.com/;
}
}
root@ubuntu:/etc/nginx/sites-enabled#ln -s /etc/nginx/sites-available/test.com test.com
root@ubuntu:/etc/nginx/sites-enabled# ll
total 8
drwxr-xr-x 2 root root 4096 Nov 12 15:17 ./
drwxr-xr-x 6 root root 4096 Nov 12 13:58 ../
lrwxrwxrwx 1 root root 34 Aug 8 16:26 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 38 Aug 9 10:53 example.com -> /etc/nginx/sites-available/example.com
lrwxrwxrwx 1 root root 35 Nov 12 14:23 test.com -> /etc/nginx/sites-available/test.com
root@ubuntu:/etc/nginx/sites-enabled# nginx -s reload