Nginx安装
一键脚本
# 会把nginx安装到/home/app/nginx里
# 创建用户
adduser nginx
# 创建临时文件目录
mkdir -p /home/app/nginx/tmp
# 安装依赖的库
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel perl perl-devel perl-ExtUtils-Embed
# 下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar xzvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
# 配置nginx
./configure --prefix=/home/app/nginx \
--user=nginx \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_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_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--http-client-body-temp-path=/home/app/nginx/tmp/client_body_temp \
--http-proxy-temp-path=/home/app/nginx/tmp/proxy_temp \
--http-fastcgi-temp-path=/home/app/nginx/tmp/fastcgi_temp \
--http-uwsgi-temp-path=/home/app/nginx/tmp/uwsgi_temp \
--http-scgi-temp-path=/home/app/nginx/tmp/scgi_temp \
--with-mail \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module
# 编译并安装
make && make install
# 启动nginx
/home/app/nginx/sbin/nginx
Linux下安装
-
安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
-
下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
-
安装nginx
要先配置一下安装选项,选项很多,参考官方链接
这里给一份自己使用的
定义了把nginx安装到/home/app/nginx
目录下,安装ssl模块cd nginx-1.14.0 ./configure --prefix=/home/app/nginx --with-http_ssl_module make make install
-
配置nginx
./conf/nginx.conf
是nginx的配置文件,官方介绍 -
启动nginx
使用命令启动
./sbin/nginx
如果在运行期间更改了配置文件,可以使用
-s
参数控制程序更新./sbin/nginx -s relaod
-
测试成功
访问
localhost:80
可以看到欢迎页,说明安装运行成功curl localhost
不成功的话请检查防火墙
常见问题
- [emerg]: getpwnam(“nginx”) failed 没有创建nginx用户导致
- 查看安装的模块
sbin/nginx -V