以下均在linux下进行:
第一步:需要安装gcc的环境。
yum install gcc-c++
第二步:nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
第三步:nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
第四步:nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
第五步: 上传nginx.tar.gz包解压(我用的是xshell和xftp)
[root@izu5nd0knyspy8z nginx]# tar zxf nginx-1.12.0.tar.gz
第六步: 使用configure命令创建一makeFile文件
./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
# -- prefix 是安装目录
第七步: 编译 --> 安装
[root@izu5nd0knyspy8z nginx-1.12.2]# make # 编译完会出现Makefile 文件夹 继续执行下面命令 [root@izu5nd0knyspy8z nginx-1.12.2]# make install # 安装完毕之后 [root@izu5nd0knyspy8z nginx-1.12.2]# cd /usr/local/nginx [root@izu5nd0knyspy8z nginx]# ll drwxr-xr-x 2 root root 4096 Dec 29 14:24 conf drwxr-xr-x 2 root root 4096 Dec 29 14:15 html drwxr-xr-x 2 root root 4096 Dec 29 14:15 sbin 这里就是启动nginx的命令 [root@izu5nd0knyspy8z sbin]# ./nginx 启动 [root@izu5nd0knyspy8z sbin]# ./nginx -s stop 停止 [root@izu5nd0knyspy8z sbin]# ./nginx -s reload 从起
注意:启动nginx之前,上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
[root@izu5nd0knyspy8z sbin]# mkdir /var/temp/nginx/client -p
至此nginx安装完毕可以启动了 可以根据IP访问 或者 域名访问
进入conf目录 编辑 vi nginx.conf # 具体详细配置,大家自己查一下 # 第一步 upstream 上面就是我(对应下面){ ip_hash; # 如果不用这个需要配置session共享(绑定ip) 具体自己查 server 127.0.0.1:8001; # tomcat的ip:端口 怎么改自己查 很简单 server 127.0.0.1:8002; server 127.0.0.1:8003 weight = 2; # weight 代表权重 越大接受的请求越多, 默认轮训分配 } # 第二部(修改就行) server { listen 80; # 监听的端口 一般就是服务器的80端口 server_name 填写域名(多种方式); #charset koi8-r; #access_log logs/host.access.log main; location / { # 配置反向代理 proxy_pass http://这里和上面对应; proxy_redirect default; } #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; #} }