nginx的总结篇以及一台nginx代理多个资源服务

一 nginx的概念和作用

1.1 概念

1.nginx是一个代理静态资源的高性能http服务器和反向代理的服务器。

1.2 作用

1.代理静态资源:可以做静态网页的http服务器。

2.反向代理、负载均衡。:把请求转发给不同的服务器

3.解决跨域

4.配置虚拟机。

一个域名可以被多个ip绑定。可以根据域名的不同吧请求转发给运行在不同端口的服务器

1.3 启动关闭

1.启动: 在nginx目录下有一个sbin目录,sbin目录下有一个nginx可执行程序: ./nginx

2.查看nginx的进程

 3.关闭

关闭命令:相当于找到nginx进程kill。

./nginx -s stop

退出命令:

./nginx -s quit

等程序执行完毕后关闭,建议使用此命令。

4.重新加载

./nginx -s reload

可以不关闭nginx的情况下更新配置文件。

二 静态资源代理

2.1 nginx的配置

1.config的配置

 2.存放的实际资源

3.访问页面

三 虚拟主机

3.1 同一台nginx,不同端口号虚拟两台服务器(ip)

nginx的配置文件:

1.第一个server块

2.第二个server块: 

 3.资源位置:

访问80:

 访问8081:

3.2  使用域名存储静态资源

1.配置nginx的配置文件

2.修改host文件

3.启动服务,进行访问 

3.3 同一台nginx,相同端口,虚拟两台不同域名的服务器(域名)

1.修改nginx配置文件

2.host文件配置

 3.页面访问,相同端口,不同域名,进行访问

 

四 反向代理:8080端口代理成80端口

tomcat的服务访问地址: http://localhost:8080/nginx-demo/index.html

被代理后的地址: http://localhost/nginx-demo/index.html

4.1 nginx配置

 4.2 tomcat的启动

 4.3  访问

五 负载均衡

见此篇文章

nginx实现负载均衡_健康平安的活着的专栏-CSDN博客

六   同一台nginx代理多个不同的静态资源

80端口 下 存储 vue的静态页面:   html/dky-guolu-vue

新建一个server块,端口为8099,创建一个存储react静态页面:   html/dky-guolu-react/;

#前端react页面
        server {
        listen       8099;
        server_name  localhost;

        location / {
            root   html/dky-guolu-react/;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

并且将react代理到80端口下,配置如下配置 :

 #前端react的页面
        location /react {
            proxy_pass http://32.32.255.239:8099/;
            #root   html;
            #index  index.html index.htm;
        }

访问地址:http://32.32.255.239:80/react/index.html

原先地址:http://32.32.255.239:8099/index.html


#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 {
    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;
       
      #悬挂vue菜单页面
        location / {
            #proxy_pass http://172.16.71.134:8080;
            root   html/dky-guolu-vue;
            index  index.html index.htm;
        }
        #门户前端
       location /frame/ {
	        proxy_pass   http://32.32.255.239:8989/frame/;
	         #root   html;
                 #index  index.html index.htm;
        }
        #调取cloudiip 
        location /cloudiip-cas {
     	         proxy_pass   http://32.32.255.241:80/;
         	 #root   html;
            	 #index  index.html index.htm;
        }
        #代理综合爆炸图-一次风机
         location /zhbz-3ycfj  {
                 proxy_pass   http://32.32.255.239:8098/;
                 #root   html;
                 #index  index.html index.htm;
        }
        #代理综合爆炸图-送风机
         location /zhbz-3sfj  {
                 proxy_pass   http://32.32.255.239:8096/;
                 #root   html;
                 #index  index.html index.htm;
        }
        #代理综合爆炸图-一次风机
         location /zhbz-3yfj  {
                 proxy_pass   http://32.32.255.239:8095/;
                 #root   html;
                 #index  index.html index.htm;
        }

        #前端react的页面
        location /react {
            proxy_pass http://32.32.255.239:8099/;
            #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;
        #}
    }
#综合-爆炸图-一次风机
	server {
        listen       8098;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dky-guolu-vue/webgl/3ycfj;
            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;
        #}
    }

#综合-爆炸图-送风机
        server {
        listen       8096;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dky-guolu-vue/webgl/3sfj;
            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;
        #}
    }
#综合-爆炸图-引风机
        server {
        listen       8095;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dky-guolu-vue/webgl/3yfj;
            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;
        #}
    }






	#综合脱硫图
	server {
        listen       8097;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dky-guolu-vue/webgl/webGL2;
            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;
        #}
    }
#前端react页面
        server {
        listen       8099;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dky-guolu-react/;
            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;
    #    }
    #}

}

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值