1、添加nginx服务进程用户
# groupadd -r nginx
# useradd -r -g nginx nginx
2、下载
记得挑选自己喜欢的版本
http://nginx.org/download
可以在远程主机直接下载
# wget http://nginx.org/download/nginx-1.9.9.tar.gz
也可以用该地址下载之后自己上传到远程主机
3、解压
# tar -zxvf nginx-1.9.9.tar.gz
4、部署
先进入到解压完成的nginx目录下
# cd nginx-1.9.9/
然后安装,最简单的安装是这样,没有添加第三方模块,不过一般都不够用
/usr/local/nginx是安装路径,可以根据需要自己修改
./configure --prefix=/usr/local/nginx
后面配置的时候会发现需要的好多模块都没有。
索性就把所有模块都安装了吧
# ./configure --prefix=/usr/local/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/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --user=nginx --group=nginx --with-pcre --with-http_v2_module --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 --with-threads --with-stream --with-stream_ssl_module
如果出现如下错误
checking for C compiler ... not found
需要执行
# yum -y install gcc gcc-c++ autoconf automake make
再次安装
可能会出现下一个错误
./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.
如果出现了,就执行这个
# yum -y install openssl openssl-devel
后面如果是这样就是执行成功了
creating objs/Makefile
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"
5、编译
# make
结尾如下
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/local/nginx/nginx-1.9.9'
6、安装
# make install
结尾是这样的话应该就是完成了
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/usr/local/nginx/nginx-1.9.9'
7、启动
参数 -c 指定了配置文件的路径,如果不加的话就是使用默认的配置文件
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
查看是否启动
# ps -ef | grep nginx
然后在浏览器输入IP 默认端口是80
看到这样的 就是成功了