linux 制作nginx 绿色 免安装 非root用户使用nginx 解压即用版本

1 篇文章 0 订阅
1 篇文章 0 订阅

nginx官方安装教程:http://nginx.org/en/linux_packages.html

前言

在linux 解压nginx压缩包就能启动。卸载直接删除目录即可,简直不要太爽。
看完这篇文章保证让你能自己制作一个nginx绿色版本包。

制作前提

1.找一台root 用户的linux机器,一般自己搭建一个虚拟机,这里就不做过多的描述了,网上有很多教程虚拟机搭建linux系统。

开始制作

# 安装基础的依赖工具
yum -y install gcc-c++ make wget

# 下载nginx模块依赖的软件包和nginx源码包
wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
wget https://zlib.net/zlib-1.2.11.tar.gz
wget http://nginx.org/download/nginx-1.16.1.tar.gz


#解压
tar -zxvf openssl-1.0.2s.tar.gz
tar -zxvf pcre-8.43.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf nginx-1.16.1.tar.gz


# 编译nginx
cd nginx-1.16.1
./configure \
   --with-openssl=../openssl-1.0.2s \
   --with-pcre=../pcre-8.43 \
   --with-zlib=../zlib-1.2.11 \
   --with-pcre-jit --user=root \
   --prefix=/root/nginx \
   --with-http_ssl_module \
   --with-http_v2_module 

# 输出如下信息说明编译配置没问题
Configuration summary
  + using PCRE library: ../pcre-8.43
  + using OpenSSL library: ../openssl-1.0.2s
  + using zlib library: ../zlib-1.2.11

  nginx path prefix: "/root/nginx"
  nginx binary file: "/root/nginx/sbin/nginx"
  nginx modules path: "/root/nginx/modules"
  nginx configuration prefix: "/root/nginx/conf"
  nginx configuration file: "/root/nginx/conf/nginx.conf"
  nginx pid file: "/root/nginx/logs/nginx.pid"
  nginx error log file: "/root/nginx/logs/error.log"
  nginx http access log file: "/root/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" 

#编译,这里要稍等一会会。
make
make install


#完成之后进入 root 打包nginx

cd /root

tar -zxcf nginx-green.tar.gz nginx

到这里就制作完成了

启动nginx

root 用户下启动

在目标主机 root 目录下 下解压nginx

#解压
tar -zxvf nginx-green.tar.gz
# 进入 启动目录
cd /root/nginx/sbin/

执行:

 ./nginx -c <nginx.conf 路径>

问题:在root用户下当然启动简单,但是非root 用户下呢

非root用户下启动 nginx

方案一:上面我们编译时指定的是/root/nginx 的目录,所以启动时会自动找/root/nginx 下的文件,会出现一些 错误。

所以这里,重新编译打包nginx 指定 非root用户nginx的home
例如: 用户为nginx 家目录为:/home/nginx

cd nginx-1.16.1
./configure \
   --with-openssl=../openssl-1.0.2s \
   --with-pcre=../pcre-8.43 \
   --with-zlib=../zlib-1.2.11 \
   --with-pcre-jit --user=nginx \
   --prefix=/home/nginx  \
   --with-http_ssl_module \
   --with-http_v2_module 
# 编译&& 安装
make && make install


打包解压 到 /home/nginx 目录下.
执行 启动命令

 nginx -c <nginx.conf 路径>

方案二:依然使用root 打包的nginx tar包,
解压指定 nginx 的home 目录 : /home/nginx/

tar -zxvf nginx-green.tar.gz -C /home/nginx/

启动时:进入 nginx/sbin/ 目录 启动 指定 -p

./nginx -p /home/nginx/nginx -c /home/nginx/conf/nginx.conf

总结:方案一、方案二 亲自验证过,方案一比较麻烦,需要重新编译指定prefix 目录,后面其他地方要使用nginx可以直接使用制作好的绿色版本nginx压缩包,使用方案二,解压启动即可

卸载直接删除 目录即可。

nginx 的配置方式这里就不讲解了,nginx已经是非常成熟的了,网上可以找到一大堆。

nginx 常用命令


./nginx  #打开 nginx
nginx -s reload|reopen|stop|quit  #重新加载配置|重启|停止|退出 nginx
nginx -t   #测试配置是否有语法错误

nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

-?,-h           : 打开帮助信息
-v              : 显示版本信息并退出
-V              : 显示版本和配置选项信息,然后退出
-t              : 检测配置文件是否有语法错误,然后退出
-q              : 在检测配置文件期间屏蔽非错误信息
-s signal       : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix       : 设置前缀路径(默认是:/usr/local/nginx/)
-c filename     : 设置配置文件(默认是:/usr/local/nginx/conf/nginx.conf)
-g directives   : 设置配置文件外的全局指令

-- 启动(不推荐):在nginx目录下有一个sbin目录,sbin目录下有一个nginx可执行程序。
./nginx

-- 启动(指定配置文件,推荐)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-- 关闭命令:相当于找到nginx进程kill。
./nginx -s stop

-- 退出命令:等程序执行完毕后关闭,建议使用此命令。
./nginx -s quit

-- 动态加载配置文件:可以不关闭nginx的情况下更新配置文件。
./nginx -s reload

-- 关闭 http 记录访问日志。
access_log off;
 或
access_log /dev/null;

-- 关闭 server 操作日志。
error_log /dev/null;

-- access.log日志按天输出。
-- 在server中 server_name 下 配置如下:
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
  set $year $1;
  set $month $2;
  set $day $3;
}
access_log logs/$year-$month-$day-access.log;

记录一下,不正确的地方请多多指教。

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
phpfind是7件套,集成最新Nginx+PHP+MySQL+SQL-Front+Zend Guard Loader+XCache。 纯绿色安装后无需再配置。支持系统服务和服务两种启动方式,自由切换。 一次性安装无需再安装,即使重做系统后亦可使用,直接点启动即可。 小巧简易迷你只有13M,常方便的搭建网站服务器。 有专门开发的控制面板进行控制程序的启停。 phpfind 2013 包括以下组件: PHP 5.3.21  web编程语言 Nginx 1.3.11  服务器 MySQL 5.5.29  数据库 SQL-Front 5.1.4.16  MySQL管理器 Zend Guard Loader 5.5.0  PHP优化器 XCache 3.0.1    PHP缓存器/优化器 eAccelerator 1.0  PHP缓存加速器 以上均为当前最新版本。 『特别注意』MySQL数据库用户名:root,密码root 1. 为了减少出错安装路径不得有空格和汉字,如有防火墙开启,会提示是否信任httpd、mysqld运行,请选择全部允许。 2. 此为Nginx+PHP方案,需要apache+php方案的请到www.phpStudy.net下载phpStudy,Lighttpd+PHP方案下载phpLight。 3. 重装系统后或相关服务丢失时,只需要点一下『运行模式-应用』即可,更改路径自动启动。 4. 可通过菜单『卸载相关服务』进行卸载相关服务。 5. 在『启动』、『停止』、『重启』三个启停按钮上右键可以有选择地进行启停,左键将控制全部的启停。 6. 菜单『phpStudy 设置』可以进行php,apche,mysql的相关设置。菜单『站点域名设置』可以进行站点及域名的添加。 7. 本程序分为安装版安装版,无论是安装还是安装,最后的效果完全一致。 8. 鉴于phpMyAdmin的导入导出功能太弱,并且大文件SQL还容量出错,故将phpMyAdmin换成SQL-Front。 系统服务和服务启动的区别: 系统服务启动:开机就会启动,适合经常使用或做服务器,无需手工启动,服务会随开机而启动,好处程序运行稳定。 服务启动:需要手动启动一下,适合偶尔经常使用一下。在不使用的情况不会启动相关进程,从而节省电脑的资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值