JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx安装与配置,有了它有备无患

wys521 2024-09-06 04:28:08 精选教程 29 ℃ 0 评论

众所周知Nginx 是一款高性能的 http 服务器/反向代理服务

器及电子邮件(IMAP/POP3)代理服务器。

由一位俄罗斯程序员开发。官方测试 nginx 能够支支撑 5 万并发链接,并且 cpu、内存等资源消耗却非常低,运行非常稳定。那么今天我们就将Nginx的安装配置过程记录下来,供大家参考。


1 Nginx下载

官方网站下载 nginx:http://nginx.org/

我们案例中使用的版本是 1.8.0 版本。

2 Nginx安装

第一步:把 nginx 的源码包nginx-1.8.0.tar.gz上传到 linux 系统

Alt+p 启动sftp ,将nginx-1.8.0.tar.gz上传

第二步:解压缩

tar zxvf nginx-1.8.0.tar.gz

第三步:进入nginx-1.8.0目录 使用 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

执行后可以看到Makefile文件



---- 知识点小贴士 ----

Makefile是一种配置文件, Makefile 一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。

---- 知识点小贴士 ----

configure参数

./configure \

--prefix=/usr \ 指向安装目录

--sbin-path=/usr/sbin/nginx \ 指向(执行)程序文件(nginx)

--conf-path=/etc/nginx/nginx.conf \ 指向配置文件

--error-log-path=/var/log/nginx/error.log \ 指向log

--http-log-path=/var/log/nginx/access.log \ 指向http-log

--pid-path=/var/run/nginx/nginx.pid \ 指向pid

--lock-path=/var/lock/nginx.lock \ (安装文件锁定,防止安装文件被别人利用,或自己误操作。)

--user=nginx \

--group=nginx \

--with-http_ssl_module \ 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)

--with-http_flv_module \ 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)

--with-http_stub_status_module \ 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)

--with-http_gzip_static_module \ 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)

--http-client-body-temp-path=/var/tmp/nginx/client/ \ 设定http客户端请求临时文件路径

--http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 设定http代理临时文件路径

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 设定http fastcgi临时文件路径

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 设定http uwsgi临时文件路径

--http-scgi-temp-path=/var/tmp/nginx/scgi \ 设定http scgi临时文件路径

--with-pcre 启用pcre库

第四步:编译

make

第五步:安装

make install

3 Nginx启动与访问

注意:启动nginx 之前,上边将临时文件目录指定为/var/temp/nginx/client, 需要在/var 下创建此 目录

mkdir /var/temp/nginx/client -p

进入到Nginx目录下的sbin目录

cd /usr/local/ngiux/sbin

输入命令启动Nginx

./nginx

启动后查看进程

ps aux|grep nginx



地址栏输入虚拟机的IP即可访问(默认为80端口)



关闭 nginx:

./nginx -s stop

或者

./nginx -s quit

重启 nginx:

1、先关闭后启动。

2、刷新配置文件:

./nginx -s reload

就是这么简单,快动手试试吧

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表