#解压之前下载的nginx源码安装包
[root@redhat7 nginx-1.8.1]# tar xzvf nginx-1.8.1.tar.gz
#进到新解压出来的nginx目录下
[root@redhat7 nginx-1.8.1]# cd nginx-1.8.1/
#安装nginx,常用编译选项说明
  • --prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
  • --conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
  • --user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--group=name类似
  • --with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configuremake来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
  • --with-zlib=PATH : 指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
  • --with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
  • --with-http_stub_status_module : 用来监控 Nginx 的当前状态
  • --with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
  • --add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译
 [root@redhat7 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl --with-pcre=/usr/local/pcre
--with-zlib=/usr/local/zlib --with-http_ssl_module
[root@redhat7 nginx-1.8.1]# make&&make install
#查看80端口的占用情况,确保没被其他程序占用
[root@redhat7 nginx-1.8.1]# netstat -nldp|grep 80
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1880/dnsmasq
udp 0 0 192.168.122.1:53 0.0.0.0:* 1880/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1880/dnsmasq
unix 2 [ ACC ] STREAM LISTENING 25908 2805/ibus-daemon @/tmp/dbus-oHuQhGwl
#启动nginx,查看新的80端口占用情况
[root@redhat7 nginx-1.8.1]# /usr/local/nginx/sbin/nginx
[root@redhat7 nginx-1.8.1]# netstat -nldp|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 97144/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1880/dnsmasq
udp 0 0 192.168.122.1:53 0.0.0.0:* 1880/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1880/dnsmasq
unix 2 [ ACC ] STREAM LISTENING 25908 2805/ibus-daemon @/tmp/dbus-oHuQhGwl
#查看nginx是否正常
[root@redhat7 nginx-1.8.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

#以上即说明我们的nginx安装成功。

设置开机启动nginx
首先,在Linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令: vim /etc/init.d/nginx 在脚本中添加如下命令:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@redhat7 ~]#chmod 755 nginx

[root@redhat7 ~]# chkconfig --add nginx
[root@redhat7 ~]# chkconfig --level 345 nginx on
[root@redhat7 ~]# chkconfig --list
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
nginx 0:关 1:关 2:关 3:开 4:开 5:开 6:关
rhnsd 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@redhat7 ~]# /etc/init.d/nginx status | start |restart |stop |reload
 

最新文章

  1. Android资源站
  2. 如何快速正确的安装 Ruby, Rails 运行环境---------------转载
  3. Maven学习-处理资源文件
  4. latex学习--基础知识
  5. Alpha版本十天冲刺——Day 2
  6. nyoj756_重建二叉树_先序遍历
  7. FastDFS+Nginx轻量级分布式
  8. c++字符串详解(转)
  9. 用ActionSupport实现验证
  10. 直接运行PowerShell脚本
  11. 今日吐槽20151208.net服务器控件
  12. Dedecms当前位置{dede:field name='position'/}修改
  13. 单列模式 (singleton pattern)
  14. createDocumentFragment
  15. Json解析要点
  16. (二十六)静态单元格(Cell)
  17. [RESTful] RESTful是什么,为什么要使用它
  18. [部署]CentOS安装MariaDB
  19. 01 python初学(注释、交互、if while for)
  20. python 实现快速排序

热门文章

  1. Assignment 2: UDP Pinger[课后作业]
  2. AngularJS 插值字符串 $interpolate
  3. 华为 mate30 安装谷歌助手
  4. Position定位相关知识了解
  5. CSS样式表及选择器相关内容(一)
  6. Dockerfile 基本命令
  7. SQL注入原理-手工联合注入查询技术
  8. Python,while循环小例子--猜拳游戏(三局二胜)
  9. lvm逻辑卷扩容报错解决
  10. dijkstra,belllman-ford,spfa最短路算法