nginx实战操作(常用命令及配置)

1. nginx介绍

在这里插入图片描述

2. nginx常用命令

	验证配置是否正确: nginx  -t
  查看Nginx的详细的版本号:nginx  -V
  查看Nginx的简洁版本号:nginx  -v
  启动Nginx:start  nginx
	快速停止或关闭Nginx:nginx   -s   stop
	正常停止或关闭Nginx:nginx   -s   quit
	配置文件修改重装载命令:nginx   -s  reload

3. nginx配置

3.1 配置代码
#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

 #1 start
	upstream linuxidc {
			server localhost:7071;
			server localhost:7072;
			server localhost:7073;
	}
   server {
       listen      7070;
       server_name  localhost;
       location / {
          # root    C:/ngtest2;
         # index  index.html index.htm;
         proxy_pass http://linuxidc;
        }
    }
# 1 end
 #2 start
   server {
       listen      7071;
       server_name  localhost;
       location / {
           root    C:/ngtest1;
         # index  index.html index.htm;
         #proxy_pass https://tms;
         #proxy_pass https://www.baidu.com/;
        }
    }
   server {
       listen      7072;
       server_name  localhost;
       location / {
           root    C:/ngtest2;
         # index  index.html index.htm;
         #proxy_pass https://tms;
        }
    }
   server {
       listen      7073;
       server_name  localhost;
       location / {
          root    C:/ngtest3;
         # index  index.html index.htm;
         #proxy_pass https://tms;
        }
    }

# 2 end
 #3 start
    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        
        #location / {
          #  root   C:\ngtest;
            #index  index.html index.htm;
            #proxy_pass https://www.baidu.com/;
       # }

        location /baidu {
            #root   html;
            #index  index.html index.htm;
            proxy_pass https://www.baidu.com/;
        }
        location /csdn {
            #root   html;
            #index  index.html index.htm;
            proxy_pass https://www.csdn.net/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # 3 end
    }
}

3.2 代码说明及效果图
3.2.1 不同端口代理不同应用
#2 start
   server {
       listen      7071;
       server_name  localhost;
       location / {
           root    C:/ngtest1;
         # index  index.html index.htm;
         #proxy_pass https://tms;
         #proxy_pass https://www.baidu.com/;
        }
    }
   server {
       listen      7072;
       server_name  localhost;
       location / {
           root    C:/ngtest2;
         # index  index.html index.htm;
         #proxy_pass https://tms;
        }
    }
   server {
       listen      7073;
       server_name  localhost;
       location / {
          root    C:/ngtest3;
         # index  index.html index.htm;
         #proxy_pass https://tms;
        }
    }

# 2 end
3.2.2 效果图

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3.2.3 同一端口号代理不同应用
 #3 start
    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        
        #location / {
          #  root   C:\ngtest;
            #index  index.html index.htm;
            #proxy_pass https://www.baidu.com/;
       # }

        location /baidu {
            #root   html;
            #index  index.html index.htm;
            proxy_pass https://www.baidu.com/;
        }
        location /csdn {
            #root   html;
            #index  index.html index.htm;
            proxy_pass https://www.csdn.net/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # 3 end
3.2.4 效果图

在这里插入图片描述

在这里插入图片描述

3.2.5 负载均衡

默认采用的轮询方式

#1 start
	upstream linuxidc {
			server localhost:7071;
			server localhost:7072;
			server localhost:7073;
	}
   server {
       listen      7070;
       server_name  localhost;
       location / {
          # root    C:/ngtest2;
         # index  index.html index.htm;
         proxy_pass http://linuxidc;
        }
    }
# 1 end
3.2.6 效果图

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述


更多知识请关注公众号:「软件老王」,IT技术与相关干货分享,回复关键字获取对应干货,java,送必看的10本“武功秘籍”;图片,送100多万张可商用高清图片;面试,送刚毕业就能月薪“20k”的java面试题,后续不断更新中,比如“软考”、“工具”等,已经在整理中。

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软件老王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值