资讯专栏INFORMATION COLUMN

在ubuntu中自定义安装nginx

孙淑建 / 1221人阅读

摘要:在中,如果使用的方式,这些都已经配置好了,默认情况下,就是开机自启动,使用自启动启动查看状态设置为系统默认启动

安装时间 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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40146.html

相关文章

  • Vagrant 系列一:安装配置

    摘要:启动,输入验证安装是否成功,如果出现版本信息表示成功。安装注意官方推荐的是。如果上述命令执行失败,需要确认是否是最新版本。和配置文件中的保持一致在目录下运行命令启动这个提示是冲突,更改即可。再执行,首次启动会有一个初始化过程查看状态。 如果是工程化开发,走正规军路子还是推荐使用 Homestead。下载Vagrant。官方下载地址 这里下载的是Windows版本的安装包。直接点击安装即...

    liuyix 评论0 收藏0
  • Centos源码安装Nginx

    摘要:一准备的安装环境下面正式开始一般我们都需要先装,前者为了重写,后者为了压缩。 一、准备nginx的安装环境 yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel yum -y install ...

    snifes 评论0 收藏0
  • 公司项目NODEJS实践0.1[ ubuntu,nodejs,nginx...]

    摘要:创建成功后进入文件夹执行执行作用创建文件,维护项目的依赖文件解释创建文件执行作用用系统的编辑器打开文件。我的技术新群上一篇前后端分离项目实践分析下一篇公司项目实践 一、前言 前端如何独立用nodeJs实现一个简单的注册、登录功能,是不是只用nodejs+sql就可以了?其实是可以实现,但离实际应用还有距离,那要怎么做才是实际可用的。 网上有很多nodeJs的示例,包括和 sql /...

    cppprimer 评论0 收藏0
  • (可用)centos 6.5 源码安装nginx

    摘要:安装库下载最新的源码包,使用下面命令下载编译和安装包添加全局变量下面正式开始一般我们都需要先装,前者为了重写,后者为了压缩。 b-devel openssl openssl--devel pcre pcre-devel yum -y install gcc pcre pcre-devel openssl openssl-devel zlib-devel gd gd-devel perl...

    赵春朋 评论0 收藏0
  • 实用贴:hadoop系统下载安装教程

    摘要:实用贴系统下载安装教程在前几篇的文章中分别就虚拟系统安装系统安装以及运行服务器的设置等内容写了详细的操作教程,本篇分享的是的下载安装步骤。我让他们去下载安装试一下,至于后来试没试就不得而知了。 实用贴:hadoop系统下载安装教程在前几篇的文章中分别就虚拟系统安装、LINUX系统安装以及hadoop运行服务器的设置等内容写了详细的操作教程,本篇分享的是hadoop的下载安装步骤。在此之...

    BenCHou 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<