Nginx

一、nginx下载安装

nginx是一款高性能的http服务器和反向代理服务器
nginx官网:https://www.nginx.com/

下载地址:http://nginx.org/en/download.html
   (linux版本点击nginx-1.19.1,windows版本点击带有windows的,pgp不知道什么东东)
   
下载解压nginx-1.18.0.zip,双击nginx-exe,浏览器运行localhost:端口(conf文件里面的listen),能看到welcome表示安装启动成功

windows
linux

二、nginx命令

查看帮助                                 nginx -h
显示版本信息                             nginx -v
显示版本和配置项信息                      nginx -V
重新打开日志文件                         nginx -s reopen
设置nginx的前缀路径                      nginx -p
启动
	通过默认的配置文件启动               /nginx/sbin/nginx
	指定配置文件启动                    /nginx/sbin/nginx -c filepath
	其他方式启动                       service nginx start       windows: nginx start       或者 nginx.exe
	
优雅退出nginx                          nginx -s quit            windows: nginx.exe -s quit 或者 nginx.exe -s stop      
快速停止                               nginx -s stop            windows:nginx.exe -s reload
停止(要先查看nginx的主进程号)
                                       kill   -quit  主进程号
                                       kill   -9     主进程号
                                       kill   -term  主进程号
                                       pkill -9 nginx
                                      service nginx stop 或者 nginx -s stop
 平滑升级
            1、编译安装新的可执行文件
            2、执行kill -usr2旧版本nginx进程号
            3、执行kill -winch旧版本nginx主进程号
  

三、nginx配置文件

1、配置文件主要区块

main(全局设置) 作用域是全局
events(nginx工作模式)
http
	upstream(负载均衡服务器设置)
	server(主机设置)
		location(URL匹配)

2、配置文件示例

http{
	upstream tuling1{          
		server 127.0.0.1:8081;     #本地服务1
		server 127.0.0.1:8082;     #本地服务2
	
	}
	upstream tuling2{          
		server 127.0.0.1:8083;     #本地服务3
		server 127.0.0.1:8084;     #本地服务4
	}
	server{       
		  location / {                                    
	            proxy_pass http://tuling;       //配置后端接口路径
		  }
	}
}

http{
	upstream tuling{          
		server 127.0.0.1:8081;     #本地服务1
		server 127.0.0.1:8082;     #本地服务2
		server 127.0.0.1:8083;     #本地服务3
	}
	server{
		  listen       80;                //用户访问端口
		  server_name  192.168.1.72;     //用户访问域名(要去host文件配置)
		  
		  location /hello/ {                                     //用户访问路径
		            proxy_pass http://127.0.0.1:8090/hello/;    //本地idea项目访问路径(实际路径)
		  }
		  location /haha/ {                                    //用户访问路径
		         proxy_pass https://www.baidu.com/;            //实际路径
		  }    
		  
		  location /012/ {                       //访问路径 
            root    html;                        //页面文件夹
            index  index.htm;                    //页面名称      所以这个静态文件在 /html/012/index.html
        }
	}
}

在这里插入图片描述

3、 原始配置文件 nginx.conf (有加一些中文说明)

#user  nobody;
#一、头
worker_processes  1;

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

#pid        logs/nginx.pid;

#二、工作模式
events {    
    worker_connections  1024;
}

# 三、剩余部分都是http的了
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

四、nginx代理模式

代理:给某个对象提供一个代理对象,并由代理对象控制源对象的引用
正向代理:代表了客户端去获取服务器资源
反向代理:代表了服务器,响应给用户

五、nginx负载均衡

在这里插入代码片

六、nginx限流

在这里插入代码片

七、nginx动静分离

在这里插入代码片

八、nginx热备

热备:不停机情况下对数据进行备份(就像热部署)

九、nginx安全认证

在这里插入代码片
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飘然生

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

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

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

打赏作者

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

抵扣说明:

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

余额充值