1. 下载niginx的 tar包
下载路径
http://nginx.org/en/download.html
也可以直接使用命令下载
wget http://nginx.org/download/nginx-1.15.1.tar.gz
2. 下载目录下解压缩
tar -zxvf nginx-1.15.1.tar.gz
3. cd 到目录里面进行处理
./configure
4. 安装时会报错 主要有:
./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=<path> option. 需要pcre ./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=<path> option. 需要zlib
一般linux里面安装了 prce和 zlib 但是没有安装devel 包 需要进行安装
yum install -y prce-devel
yum install -y zlib-devel
5. 再次执行 ./confiure命令成功
反馈安装信息
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library 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"
6. 执行 make 和 make install 进行安装
make and make install
9. 创建软连接
ln /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
10. 直接启动
nginx
遇到报错如图示时
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
nginx: [emerg] still could not bind()
11. 修改配置文件
查看配置文件位置 nginx -t
结果为
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
修改配置文件
vim /usr/local/nginx/conf/nginx.conf
将端口绑定修改一下
再次启动即可