码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-07-14 00:23:37      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:out   www   listen   net   命令   sha   oss   quit   eve   

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 效果图

技术图片

技术图片

技术图片


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

标签:out   www   listen   net   命令   sha   oss   quit   eve   

原文地址:https://www.cnblogs.com/ruanjianlaowang/p/11182631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!