先记录,后续整理
root安装,nginx用户只存放自定义nginx启动脚本
注意文中软件版本,版本差异会有不兼容,在install会报错
环境清单:
服务器版本:CentOS 7.6
软件版本:文中有写
-
创建目录
useradd nginx mkdir -p /var/cache/nginx/{client_temp,fastcgi_temp,proxy_temp,scgi_temp,uwsgi_temp} mkdir -p /var/log/nginx cd /home/nginx
-
安装依赖
yum install -y gcc gcc-c++ pcre-devel openssl-devel pcre openssl zlib perl-libs
-
安装插件
#nginx-1.12.2.tar.gz下载 cd /home/nginx wget http://nginx.org/download/nginx-1.12.2.tar.gz tar -zxvf nginx-1.12.2.tar.gz #nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz下载 cd /home/nginx wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz tar -zxvf master.tar.gz #下载lua_nginx_module模块版本 lua-nginx-module-0.10.2,https://github.com/openresty/lua-nginx-module/tags mkdir -p /usr/local/nginx/src cd /usr/local/nginx/src wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz tar -xzvf v0.10.9rc7.tar.gz #下载ngx_devel_kit 版本 ngx_devel_kit-0.2.19,https://github.com/simpl/ngx_devel_kit/tags cd /usr/local/nginx/src wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz tar -xzvf v0.3.0.tar.gz #下载LuaJIT 版本 LuaJIT-2.1.0-beta2,http://luajit.org/download.html cd /usr/local/nginx/src wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz tar zxf LuaJIT-2.0.2.tar.gz cd LuaJIT-2.0.2 make PREFIX=/usr/local/luajit make install PREFIX=/usr/local/luajit #设置环境变量 export LUAJIT_LIB=/usr/local/luajit/lib export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0 #./configure --prefix=/usr/local/nginx --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --add-module=/usr/local/nginx/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/nginx/src/lua-nginx-module-0.10.2 #nginx-sticky-module-ng插件会话保持插件,解决负载过程中cookie问题 tar zxf master.tar.gz mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-module-ng
-
安装
cd /home/nginx/nginx-1.12.2 ./configure --prefix=/usr/local/nginx --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-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6 --with-stream --add-module=../nginx-sticky-module-ng --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --add-module=/usr/local/nginx/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/nginx/src/lua-nginx-module-0.10.9rc7 make && make install
-
启动
/usr/local/nginx/sbin/nginx
-
测试
vi /usr/local/nginx/conf/nginx.conf location / { default_type text/plain; content_by_lua 'ngx.say("hello world")'; root html; index index.html index.htm; }
访问页面
http://ip
效果图:
至此,安装成功,看完觉得有用请点个赞!