Ubuntu安装Nginx 并转发请求到Tomcat

一. 安装步骤

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 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值