在ubuntu中自定义安装nginx

发布时间:2019-06-14 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了在ubuntu中自定义安装nginx脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
  • 安装时间 2018-10-01
  • 安装环境 win10+virtualbox+ubuntu server 16,安装在虚拟机ubuntu server中

安装

下面定义成一句命令,适合在docker 中使用
# 安装库
sudo apt-get update && sudo apt-get install -y unzip libluaJIT-5.1-dev libluajIT-5.1-2 oPEnssl libssl-dev build-essential && 
# 下载
wget http://nginx.org/download/nginx-1.8.0.tar.gz && 
wget https://github.COM/openresty/lua-nginx-module/Archive/v0.9.15.tar.gz && 
wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz && 
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz && 
wget https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz && 
wget https://github.com/openresty/redis2-nginx-module/archive/v0.11.zip && 
wget ftp://ftp.csx.cam.ac.uk/pub/Software/PRogramming/pcre/pcre-8.38.tar.gz && 
wget https://github.com/iMega/nginx-eval-module/archive/master.zip && 
wget http://zlib.net/zlib-1.2.11.tar.gz && 

# 解压
tar -xzvf nginx-1.8.0.tar.gz && 
tar -xzvf v0.9.15.tar.gz && 
tar -xzvf LuaJIT-2.0.3.tar.gz && 
tar -xzvf v0.2.19.tar.gz && 
tar -xzvf v0.61.tar.gz && 
unzip v0.11.zip && 
tar -zxvf pcre-8.38.tar.gz && 
unzip master.zip && 
tar -zxvf zlib-1.2.11.tar.gz && 

export LUAJIT_LIB=/usr/include/luajit-2.0  && 
export LUAJIT_INC=/usr/include/luajit-2.0  && 

# 配置
cd nginx-1.8.0 && 
./configure 
--conf-path=/etc/nginx/nginx.conf 
--with-ld-opt='-Wl,-rpath,/usr/include/luajit-2.0' 
--add-module=../ngx_devel_kit-0.2.19 
--add-module=../redis2-nginx-module-0.11 
--add-module=../lua-nginx-module-0.9.15 
--with-pcre=../pcre-8.38 
--with-zlib=../zlib-1.2.11 
--with-http_ssl_module 
--with-http_stub_status_module 
--add-module=../nginx-eval-module-master 
--add-module=../echo-nginx-module-0.61 && 

#configuration summary
#  + using PCRE library: ../pcre-8.38
#  + using System OpenSSL library
#  + using zlib library: ../zlib-1.2.11

#  nginx path prefix: "/usr/local/nginx"
#  nginx binary file: "/usr/local/nginx/sbin/nginx"
#  nginx modules path: "/usr/local/nginx/modules"
#  nginx configuration prefix: "/etc/nginx"
#  nginx configuration file: "/etc/nginx/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"

# 编译
# 如果报错 configure: error: You need a C++ compiler for C++ support.得先安装build-essential
make -j2 && 

# 安装
sudo make install && 


rm -f nginx-1.8.0.tar.gz && 
rm -f v0.9.15.tar.gz && 
rm -f LuaJIT-2.0.3.tar.gz && 
rm -f v0.2.19.tar.gz && 
rm -f v0.61.tar.gz && 
rm -f v0.11.zip && 
rm -f pcre-8.38.tar.gz && 
rm -f master.zip && 
rm -f zlib-1.2.11.tar.gz && 

rm -rf /ngx_devel_kit-0.2.19 && 
rm -rf /redis2-nginx-module-0.11 && 
rm -rf /lua-nginx-module-0.9.15 && 
rm -rf /pcre-8.38 && 
rm -rf /zlib-1.2.11 && 
rm -rf /nginx-eval-module-master && 
rm -rf /echo-nginx-module-0.61

测试

sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx 
sudo nginx -c /etc/nginx/nginx.conf

在win10浏览器中输入127.0.0.1,正常

定义成服务

// 文件若不存在,会自动创建
sudo vim /lib/systemd/system/nginx.service

内容如下

[unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

开机自启动

自从 Ubuntu 15.04 之后,就已经开始默认使用 systemd 对应的 systemctl 命令。
在 Ubuntu/Debian中,如果使用apt-get install nginx 的方式,这些都已经配置好了,默认情况下,就是开机自启动,使用 systemctl enable nginx自启动

  • 启动: systemctl start nginx
  • 查看状态:systemctl status nginx
  • 设置为系统默认启动: systemctl enable nginx

脚本宝典总结

以上是脚本宝典为你收集整理的在ubuntu中自定义安装nginx全部内容,希望文章能够帮你解决在ubuntu中自定义安装nginx所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。