
1. nginx源码包的下载
nginx官方下载地址:http://nginx.org/
选择你要安装的nginx版本,这里,我选择的是 nginx-1.10.2 。
具体的下载链接为:http://nginx.org/download/nginx-1.10.2.tar.gz
可以在其他电脑下载好,通过ftp软件传给要安装的linux电脑。也可以直接在linux电脑上使用wget命令下载。这里我们使用后一种方式。
在linux的根目录,创建一个多级空目录 /my_package/source,用来存放下载的源码包。
mkdir -p /my_package/sourcecd /my_package/source12
执行下载命令:
wget http://nginx.org/download/nginx-1.10.2.tar.gz1
下载完成后,在 /my_package/source 目录中,就有了 nginx-1.10.2.tar.gz 源码包压缩文件。
2. nginx的安装与配置
2.1 准备工作
安装nginx之前,需要先安装pcre库。如果你的linux系统中没有pcre,需要先进行安装。
这里,我们使用yum工具,在线快速安装pcre:
yum -y install pcre
yum -y install pcre-devel12
可以通过下面的命令,找到已安装的pcre和pcre-devel的位置:
rpm -ql pcre
rpm -ql pcre-devel或
find / -name "*pcre*"1234
2.2 nginx的安装
配置nginx安装的参数,比如:安装路径,指定依赖库的具体位置等。
这里我们使用默认安装配置:
tar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2./configure123
如果这一步执行正确,在提示信息中会告知nginx将要安装的位置、可执行文件的位置等,如下:
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"12345678910111213
如果这一步出错了,根据错误提示信息解决问题后,使用 make clean 命令,清除产生的临时文件,再来重新执行 ./configure
如果想查看具体可以配置哪些安装参数,可以使用下面的命令查看:
./configure --help1
编译和安装
makemake install12
到此,nginx的源码包就安装完毕了。
2.3 nginx的配置
如果想修改nginx的配置文件,可使用下面的命令:
vi /usr/local/nginx/conf/nginx.conf1
3. nginx的常用命令
检查测试nginx的配置信息是否正确
/usr/local/nginx/sbin/nginx -t1
启动nginx
/usr/local/nginx/sbin/nginx1
启动nginx服务器后,可以使用下面的命令检测nginx是否启动成功,并查看nginx的端口、主进程号、进程名称等信息。
netstat -tlunp1
也可以使用下面的命令检测nginx是否启动成功,并查看nginx的主进程和子进程的详细信息。
ps aux | grep nginx1
ps aux 命令(a代表前台进程,x代表后台进程,u代表进程的发起者)列出的进程信息中,主要包含以下信息:USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 。这里,简单说明一下:
USER:表示进程的发起者,也就是说,进程是哪个用户产生的。
PID:表示进程的id,也称作,进程号。%CPU:表示进程占用的CPU资源的百分比。%MEM:表示进程占用的物理内存的百分比。
VSZ:表示进程占用的虚拟内存的大小,单位KB。
RSS:表示进程占用的实际物理内存的大小,单位KB。
TTY:表示进程是在哪个终端中运行的。其中tty1到tty7代表本地控制台终端,tty1到tty6是本地的字符界面终端,tty7是图形终端。pts/0-255代表虚拟终端(即远程登录终端)。
STAT:表示进程的状态。常见的状态有:R 运行;S 睡眠;T 停止;s 包含子进程;+ 位于后台。
START:表示进程是在什么时间启动的。
TIME:表示进程占用CPU的运算时间,值越大,越耗费资源。
COMMAND:表示产生该进程的命令(通过它可以识别正在运行的进程名)。1234567891011
成功启动nginx后,就可以在本地电脑或其他电脑中访问你的nginx服务器中的网站了。
本地电脑(即nginx所在的电脑)的访问方式:curl 127.0.0.1
其他电脑(局域网内)的访问方式:打开浏览器,输入nginx服务器的局域网IP即可。12
为了更方便的使用 /usr/local/nginx/sbin 中的命令,
我们将其加入linux系统的环境变量,即修改文件 /etc/profile,在最后加入下面的代码:
export PATH="/usr/local/nginx/sbin:$PATH"1
保存退出后,执行命令:source /etc/profile 可使该配置文件立即生效。
关闭nginx
nginx -s stop 快速关闭nginx
nginx -s quit 平滑关闭nginx
kill -s QUIT 11247 通过linux的kill命令杀死nginx进程,11247为nginx的主进程号123
重新加载nginx的配置文件
nginx -s reload 修改了nginx的配置文件后,可以使用该命令让新的配置立即生效,而不用重启整个nginx服务器
希望我的方法能够帮助到你
安装第一步 下载并解压Nginx压缩包
从Nginx官网下载Nginx,或者在Linux上执行wget http://nginx.org/download/nginx-1.10.1.tar.gz命令直接下载
解压nginx-1.10.1.tar.gz文件:
tar zxvf nginx-1.10.1.tar.gz
1
1
第二步 配置
cd nginx-1.10.1
./configure --prefix=/usr/local/nginx
1
2
1
2
注意:
① 如果之前没有安装C compiler(C 编译器),这一步将报如下错误信息:
xueliang@dev:~/download/nginx-1.10.1$ ./configure –prefix=/usr/local/nginx
checking for OS
+ Linux 4.2.0-27-generic x86_64
checking for C compiler … not found
./configure: error: C compiler cc is not found
xueliang@dev:~/download/nginx-1.10.1$
可以参考这篇文章安装C compiler,然后继续下面的 *** 作
② 如果之前没有安装PCRE,这一步将报如下错误信息:
checking for PCRE library … not found
checking for PCRE library in /usr/local/ … not found
checking for PCRE library in /usr/include/pcre/ … not found
checking for PCRE library in /usr/pkg/ … not found
checking for PCRE library in /opt/local/ … not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using –without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.
xueliang@dev:~/download/nginx-1.10.1$
③ 如果之前没有安装zlib,这一步将报如下错误信息:
checking for md5 in system md library … not found
checking for md5 in system md5 library … not found
checking for md5 in system OpenSSL crypto library … not found
checking for sha1 in system md library … not found
checking for sha1 in system OpenSSL crypto library … not found
checking for zlib library … not found
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib= option.
xueliang@dev:~/download/nginx-1.10.1$
也可以跳过此步,执行默认安装,--prefix的默认值为/usr/local/nginx,Nginx官网对此有说明:Building nginx from Sources
一、下载→编译→安装→启动1.下载nginx最新版
到官方网站上下载最新的tar.gz包
直接下载nginx的url为http://nginx.org/download/nginx-{version}.tar.gz,其中{version}为nginx的版本号
命令:[root@localhost ~]# wget http://nginx.org/download/nginx-1.9.14.tar.gz
2.解压文件
[root@localhost ~]# tar -zvxf nginx-1.9.14.tar.gz
3.进入nginx解压目录
[root@localhost ~]# cd nginx-1.9.14
4.使用参数进行编译,后面会给出编译参数的具体解释
[root@localhost nginx-1.9.14]# ./configure –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-http_ssl_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-mail –with-mail_ssl_module –with-file-aio –with-ipv6 –with-http_v2_module
5.执行编译过程
[root@localhost nginx-1.9.14]# make &&make install
6.配置nginx.conf
7.启动nginx
[root@localhost nginx-1.9.14]# nginx
二、编译参数
–prefix=path
定义保存服务器文件的目录。这个目录同时将作用于nginx.conf配置文件中配置的相对路径(但不包括源码库的路径)。默认值为/usr/local/nginx。
–sbin-path=path
设置nginx可执行文件的名称,该名称只在安装期间使用。默认值是prefix/sbin/nginx
–conf-path=path
设置nginx.conf配置文件的名称。如果需要,nginx可以使用不同的配置文件启动,你可以通过命令行参数 -c file启动。默认文件名为prefix/conf/nginx.conf
–pid-path=path
设置nginx.pid文件的名称,nginx.pid用于存储主进程的进程ID。安装后,该文件名称可以在nginx.conf的pid指令中修改。默认为prefix/logs/nginx.pid
–error-log-path=path
设置重要的错误、警告以及诊断文件的名字。安装后,可以通过nginx.conf的error_log指令修改。默认为prefix/logs/error.log
–http-log-path=path
记录主要请求日志的名称,安装后通过access_log指令修改。默认为prefix/logs/access.log
–user=name
设置工作进程的用户名,安装后可以通过user指令修改。默认值为nobody
–group=name
设置工作进程的用户组,安皇后可以通过user指令修改,默认与user相同。
–with-xxx_module
安装xxx模块,这些模块可以在nginx文档中找到。
–without-xxx_module
不安装xxx模块(有些模块是默认安装的,如果不想安装,可以通过这个参数屏蔽),这些模块可以在nginx文档中找到。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)