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



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

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

时间: 2024-08-10 02:54:04

nginx实战操作(常用命令及配置)的相关文章

linux的常用命令和配置

1.tar.gz包解压 [[email protected] crawler]# ls com.ericsson.cdm.crawler-0.0.1-SNAPSHOT-dist.tar.gz [[email protected] crawler]# tar zxvf com.ericsson.cdm.crawler-0.0.1-SNAPSHOT-dist.tar.gz com.ericsson.cdm.crawler-0.0.1-SNAPSHOT/lib/log4j-1.2.14.jar ...

nginx: [alert] kill(1668, 1) failed (3: No such process)的解决办法及nginx服务常用命令总结

[问题描述] 更改完nginx.conf文件后,执行/application/nginx/sbin/nginx -s reload命令重新加载配置文件,报以下错误信息: nginx: [alert] kill(1668, 1) failed (3: No such process) 提示没有相关进程. [解决] 其实这个问题很低级的说,就是我之前压根就没有启动nginx服务,执行/app/nginx/sbin/nginx,开启nginx服务后,重新加载nginx配置,一切正常! [nginx服务

docker常用命令及配置修改

docker修改国内源仓库地址: vim /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"] } docker常用命令 docker --help:获取docker帮助 docker container: 创建docker镜像 镜像管理: docker image --help ls : 列出镜像 images : 查看所有镜像信息 history : 查看

Maven 插件 maven-tomcat7-plugin - 常用命令及配置

常用命令 tomcat7:deploy 说明:部署 WAR 到 Tomcat tomcat7:help 说明:查看插件帮助信息 tomcat7:run 说明:支行当前项目 配置 <project> ... <build> <!-- To define the plugin version in your parent POM --> <pluginManagement> <plugins> <plugin> <groupId&g

Django常用命令及配置(Django 1.8.6)

常用命令 #新建Django项目 django-admin startproject mysite(项目名) #新建一个APP cd mysite python manager.py startapp app01(app名) #同步数据库 python manage.py makemigrations python manage.py migrate #使用开发服务器 python manage.py runserver 0.0.0.0:8000 #清空数据库 python manage.py

Redis常用命令与配置

常用命令 测试客户端与服务器是否正常连接:ping   ( 补:返回pong表示成功 ) 正则获取键:keys pattern 判断一个键是否存在:exists key 删除一个键:del key 获取键的类型:type key 清空当前数据库:flushdb 返回一个键的剩余时间:ttl key   ( 补:当 key 存在但没有设置剩余生存时间时,返回 -1 .当key不存在返回 -2 .) 设置一个键的剩余时间:expire key seconds 常用配置 配置文件在安装的根目录下,默认

linux iptables常用命令之配置生产环境iptables及优化

在了解iptables的详细原理之前,我们先来看下如何使用iptables,以终为始,有可能会让你对iptables了解更深 所以接下来我们以配置一个生产环境下的iptables为例来讲讲它的常用命令 第一步:清空当前的所有规则和计数 iptables -F #清空所有的防火墙规则 iptables -X #删除用户自定义的空链 iptables -Z #清空计数 第二步:配置允许ssh端口连接 iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport

Nginx 模块常用命令介绍

本次的命令资料全部来自官网除全局定义以及events,地址:https://nginx.org Nginx 配置组成: ...              #全局块 events {         #events块    ... } http      #http块 {     ...   #http全局块     server        #server块     {          ...       #server全局块         location [PATTERN]   #lo

maven 常用命令和配置

一.maven配置 1.1镜像配置:在文件settings.xml中配置 <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> 其他国