windows nginx 初体验


下载安装

链接 http://nginx.org/en/download.html

解压运行 进入相应的目录下,执行 start nginx 启动;nginx.exe -s reload 重启;(修改nginx需要重启)


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 {
    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 ^~ /api/login {
          proxy_pass   http://127.0.0.1:8899;
        }
		
		location ^~ /api {
          proxy_pass   http://cymanservice;
        }
		
		location ^~ /test {
          proxy_pass   http://cymantest;
        }
		
		
		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;
        }

    }

	upstream cymanservice {
	  #餐饮后端管理系统
	  server 127.0.0.1:8899 weight=1 max_fails=2 fail_timeout=30;
	}
	
	upstream cymantest {
	  #餐饮后端管理系统
	  server 127.0.0.1:8899 weight=1 max_fails=2 fail_timeout=30;
	}
	

}


index.html







Welcome to nginx!



Welcome to nginx!

Thank you for using nginx.

当你看到这句话的时候,说明我已经初步掌握了nginx

后台应用

IndexController

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :lichuankang
 * @date :Created in 2022/2/9 15:25
 * @description :
 */
@RestController
@RequestMapping(value = "/api")
public class IndexController {

    @RequestMapping(value = "/login")
    public String login() {
        System.out.println("IndexController login   is run");
        return "ok!!!";
    }

    @RequestMapping(value = "/logout")
    public String logout() {
        System.out.println("IndexController logout   is run");
        return "ok!!!";
    }
}

TestController

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :lichuankang
 * @date :Created in 2022/2/9 15:46
 * @description :
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {

    @RequestMapping(value = "/test111")
    public String test111() {
        System.out.println("TestController test111   is run");
        return "ok!!!!";
    }

    @RequestMapping(value = "/test222")
    public String test222() {
        System.out.println("TestController test222   is run");
        return "ok!!!!";
    }
}

application.properties

server.port=8899

浏览器访问: http://localhost/