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