Nginx - 01 - Nginx初体验

版权声明:本文为博主原创文章,可以转载,但请注明出处。 https://blog.csdn.net/Simba_cheng/article/details/81839271

首先下载Nginx,这里电脑太垃圾,没法装虚拟机,所以只能用Windons版本的Nginx。

安装包下载地址:http://nginx.org/en/download.html

下载下来,然后解压;

然后双击 nginx.exe就可以了。

在浏览器中输入:http://127.0.0.1/ 或者 loclahost,出现以下页面标示成功:

一开始以为windows上,nginx的命令没法使用,试了一下,还可以使用

运行停止命令:nginx.exe -s stop

好的,到这里,Nginx就算是安装完毕了。

既然是要测试Nginx,那咱们的有两个HTTP程序,用来发布服务。

为了方便,我使用的是SpringBoot

两个http程序发布的地址是:

http://localhost:9000/sayInfo

http://localhost:9001/hello

接下来,先把刚才启动的nginx停止,然后打开nginx-1.14.0\conf 目录下的nginx.conf文件,

友情提醒下,最好先备份一份,供以后学习继续使用。

删除无用配置之后,我的配置文件是这样子的:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
	
    sendfile        on;
    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
		
		location /sayInfo {
			proxy_pass http://localhost:9000/sayInfo;
		}
		
		location /hello {
			proxy_pass http://localhost:9001/hello;
		}
		
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

监听80端口

根据不同的url路径,走不同的请求分支

保存配置文件,接着启动nginx;

由于咱们监听80端口,所以url变成了这样子:

http://127.0.0.1/sayInfo

http://127.0.0.1/hello

 

nginx帮我们做了请求转发

猜你喜欢

转载自blog.csdn.net/Simba_cheng/article/details/81839271