linux网络服务[nginx]——————nginx中常用命令、nginx的配置文件、nginx反向代理跳转到后端的tomcat、实现nginx 的反向代理不同访问路径跳转到不同后端端口

1.nginx中常用命令

1)命令位置:

[root@nginx ~]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ls
nginx

2)查看nginx版本号:

[root@nginx sbin]# ./nginx -v
nginx version: nginx/1.17.4

3)关闭nginx:

[root@nginx sbin]# ./nginx -s stop
[root@nginx sbin]# ps aux | grep nginx
root     17470  0.0  0.0 112648   960 pts/1    S+   14:18   0:00 grep --color=auto nginx

4)启动nginx:

[root@nginx sbin]# ./nginx 
[root@nginx sbin]# ps aux | grep nginx
root     17480  0.0  0.0  20504   612 ?        Ss   14:19   0:00 nginx: master process ./nginx
nobody   17481  0.0  0.0  23044  1376 ?        S    14:19   0:00 nginx: worker process
root     17483  0.0  0.0 112648   960 pts/1    S+   14:19   0:00 grep --color=auto nginx

5)重加载:修改了配置文件的内容,让配置文件重新加载生效

[root@nginx sbin]# ./nginx -s reload

2. nginx的配置文件

1)配置问家的位置:

[root@nginx conf]# vim /usr/local/nginx/conf/nginx.conf

2)全局块:从配置文件开始到 events 块之间的内容,主要会设置一些影响 nginx 服务器整体运行的配置指令,主要包括配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等。

#user  nobody;
worker_processes  1; # nginx处理并发的数量

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

2)event块:

events {
   
    worker_connections  1024; # 支持最大的连接数
}

4)http块:

http {
   
    include       mime.types;
    default_type  application/octet-stream;
    server {
   # 这块和虚拟主机有密切关系,虚拟主机从用户角度看,和一台独立的硬件主机是完全一样的,该技术的产生是为了节省互联网服务器硬件成本
        listen       80; # 监听80端口
        server_name  localhost; # 主句名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
    # 
            root   html;
            index  index.html index.htm;
        }

3. 实现nginx 的反向代理跳转到后端的tomcat

实现的效果:在浏览器输入nginx地址,调转到第二台系统的tomcat主页中:

实验准备:

  • 一台nginx反向代理服务器:172.25.5.10/24
  • 一台tomcat服务器:172.25.5.15/24
  • 一台测试机

3.1 安装后端tomcat服务器

1)解压tomcat:

[root@tomcat ~]# ls
anaconda-ks.cfg               initial-setup-ks.cfg  
apache-tomcat
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值