安装依赖
sudo apt install libgd-dev
下载nginx
wget http://nginx.org/download/nginx-1.22.1.tar.gz
解压nginx
tar -zvxf nginx-1.22.1.tar.gz
编译安装
cd nginx-1.22.1
编译并指定安装位置,执行安装之后会创建指定文件夹/www/env/nginx
./configure --prefix=/www/env/nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module
结果:
nginx常用命令
nnginx-s reload修改配置后重新加载生效
快速停止nginx
nginx-s stop
nginx-s start
启动nginx
nginx-s quit完
整有序的停止nginx
查看nginx的版本nginx-v
nginx-V
查看版本和nginx的配置选项
nginx-t-c/path/to/nginyx.con以测试nginx
配置文件是否正确重新打开日志文件
nginx-s reopen、
启动nginx: ps -ef | grep nginx
public class IndexNginxController {
@Value("${server.port}")
private String port;
@RequestMapping("/")
public ModelAndView index(){
ModelAndView model = new ModelAndView();
model.addObject("port", port);
model.setViewName("index");
return model;
}
}
在该Controller
类中,存在一个成员变量:port
,它的值即是从application.properties
配置文件中获取server.port
值。当出现访问/
资源的请求时,跳转前端index
页面,并将该值携带返回。
<html>
<head>
<title>Nginx演示页面</title>
<link href="nginx_style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div style="border: 2px solid red;margin: auto;width: 800px;text-align: center">
<div id="nginx_title">
<h1>$hello world 192.16.10.10{port}号!</h1>
</div>
</div>
</body>
</html>
工作准备就绪后,再修改一下nginx.conf
的配置即可.
所有的前提工作准备就绪,紧接着再启动Nginx
,然后再启动两个web
服务,第一个WEB
服务启动时,在application.properties
配置文件中,将端口号改为配置中的第一个端口号,第二个WEB
服务启动时,将其端口号改为第二个端口号