#解压之前下载的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
 

Nginx服务器的安装的更多相关文章

  1. Nginx 服务器的安装部署(CentOS系统)

    1.准备安装环境yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-develgcc编译器 ...

  2. windows环境下nginx服务器的安装与配置

    转载至:http://www.cnblogs.com/hxxy2003/archive/2012/09/20/2695254.html nginx服务器是一个高性能的HTTP和反向代理服务器,它以稳定 ...

  3. Nginx服务器的安装和卸载

    Nginx的安装 安装Nginx之前,需要先获取Nginx的安装文件.我们可以在http://nginx.org/en/download.html获取各个版本的Nginx安装文件.大家可以按照自己的需 ...

  4. Linux_CentOS 7下Nginx服务器的安装配置

    1.安装 1.1 配置epel yum 源 wget http://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm ...

  5. LINUX学习--nginx服务器的安装

    一.安装环境 操作系统CentOS6.8 关闭SeLinux和iptables防火墙 二.网络yum源 将下面的软件下载到  /etc/yum.repos.d/   的目录下 官方基础:http:// ...

  6. Linux系统上Nginx服务器的安装与配置

    前言: 详细步骤移步菜鸟教程 一. 安装Nginx,注意虚拟机与宿主机的网络连通性 l  安装编译工具及库文件(zlib库. ssl) yum -y install make zlib zlib-de ...

  7. [Nginx]实战Nginx:Nginx服务器的安装与配置

    ----------------------------------------------------------------------------------------------- Ngin ...

  8. 在Nginx服务器上安装SSL证书

    配置nginx 1.下载证书文件 2.在nginx的conf目录中创建目录cert目录,并将证书文件拷贝进去. 3.配置nginx.conf,完整的nginx.conf如下: #user nobody ...

  9. Linux下安装Nginx服务器

    安装Nginx之前,首先要安装好编译环境gcc和g++,然后以CentOS为例安装Nginx,安装Nginx需要PRCE库.zlib库和ssl的支持,除了ssl外其他的我们都是去官网下载: Nginx ...

随机推荐

  1. npm和Node.js简介

    Node.js Node.js是JavaScript的一种运行环境,是对Google V8引擎进行的封装.是一个服务器端的javascript的解释器.Node.js允许通过JavaScript和一系 ...

  2. 学习vue生命周期

    首先,每个Vue实例在被创建之前都要经过一系列的初始化过程,这个过程就是vue的生命周期.首先看一张图吧~这是官方文档上的图片相信大家一定都会很熟悉: 可以看到在vue一整个的生命周期中会有很多钩子函 ...

  3. Html-元素类型笔记

    注意点: 元素类型分为 块级元素 和 行内元素 块级元素: 在网页中以块的形式显示,默认情况都会占据一行,两个相邻的块级元素不会出现并列显示的元素,按照顺序自上而下排列. 块级元素可以定义自己的宽度和 ...

  4. 四、Linux_用户切换

    四.用户切换 # 切换用户的命令为: su username # 从普通用户切换到root用户,还可以使用命令: sudo su

  5. SLF4J: Failed to load class "org.slf4j.impl.StaticLo

    今天在修改项目是修改了pom中的配置启动后提示下面的错误, SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder&qu ...

  6. vsftpd配置文件

    一.默认配置 1. 允许匿名用户和本地用户登录 anonymous_enable=YES local_enable=YES 2. 匿名用户使用的登录名为ftp或anonymous,密码为空:匿名用户不 ...

  7. 【Flask】 python学习第一章 - 4.0 钩子函数和装饰器路由实现 session-cookie 请求上下文

    钩子函数和装饰器路由实现 before_request 每次请求都会触发 before_first_requrest  第一次请求前触发 after_request  请求后触发 并返回参数 tear ...

  8. spring的@Scheduled定时任务,同一时间段的定时任务只会执行一个,其余的会被阻塞,@Scheduled注解定时任务并发执行解决办法,即多线程运行定时任务

    原文:https://blog.csdn.net/qq_35937303/article/details/88851064 现有两个定时任务 @Component("aa") pu ...

  9. nano的简单笔记

    CTRL+c 显示行数信息 ctrl + _ 到某行 alt +m 移动光标功能 alt+y 语法矫正功能

  10. python的pandas库读取csv

    首先建立test.csv原始数据,内容如下 时间,地点 一月,北京 二月,上海 三月,广东 四月,深圳 五月,河南 六月,郑州 七月,新密 八月,大连 九月,盘锦 十月,沈阳 十一月,武汉 十二月,南 ...