1.8LNMP环境安装Nginx

Nginx服务器安装和配置

1、安装pcre软件包

[[email protected] ~]# rpm -qa | grep pcre
[[email protected] ~]# yum -y install pcre

2、创建nginx用户

[[email protected] ~]# useradd -s /sbin/nologin nginx
[[email protected] ~]# passwd nginx
Changing password for user nginx.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

3、nginx编译参数

--user    指定启动程序所属用户

--group    指定组

--prefix    指定安装路径

--sbin-path    设置nginx二进制文件的路径名

--conf-path    指定配置文件路径

--error-log-path    错误日志文件路径

--http-log-path    指定访问日志文件路径

--http-client-body-temp-path    设置存储HTTP客户端请求主体的临时文件路径

--http-proxy-temp-path    设置存储HTTP代理临时文件的路径

--http-fastcgi-temp-path    设置存储HTTP fastcgi的临时文件的路径

--pid-path    设置nginx.pid文件路径

--lock-path    设置nginx.lock文件路径

--with-openssl    启用SSL

--with-pcre    启用正则表达式

--with-http_stub_status_module    安装可以监控nginx状态的模块

--with-http_ssl_module    启用SSL支持

--with-http_gzip_static_module    启用gzip压缩

4、安装nginx

[[email protected] nginx-1.9.6]# ./configure \
> --user=nginx \
> --group=nginx \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --http-client-body-temp-path=/tmp/nginx/client_body \
> --http-proxy-temp-path=/tmp/nginx/proxy \
> --http-fastcgi-temp-path=/tmp/nginx/fastcgi \
> --pid-path=/var/run/nginx.pid \
> --lock-path=/var/lock/subsys/nginx \
> --with-http_stub_status_module \
> --with-http_ssl_module \
> --with-http_gzip_static_module \
> --with-pcre \
> --with-http_realip_module \
> --with-http_sub_module

[[email protected] nginx-1.9.6]# make && make install

[[email protected] nginx-1.9.6]# ls /usr/local/nginx/
html

检查配置

[[email protected] nginx-1.9.6]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
[[email protected] nginx-1.9.6]# mkdir /tmp/nginx/client_body -p
[[email protected] nginx-1.9.6]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动nginx

[[email protected] nginx-1.9.6]# nginx
[[email protected] nginx-1.9.6]# netstat -tlnp |grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4554/nginx

5、查看nginx版本及编译参数

[[email protected] nginx-1.9.6]# nginx -V
nginx version: nginx/1.9.6
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-http_sub_module

6、控制Nginx服务器

启动:nginx

停止:nginx -s stop

退出:nginx -s quit

重新打开:nginx -s reopen

重新加载配置:nginx -s reload

7、配置nginx启动脚本

[[email protected] ~]# vim /etc/init.d/nginx

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"

#Source networking configuration
. /etc/sysconfig/network
# Check networking is up
[ ${NETWORKING} = "no" ] && exit 0
[ -x $NGINX_SBIN ] || exit 0

start() {
        echo -n $"Starting $prog: "
        touch /var/lock/subsys/nginx
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /var/lock/subsys/nginx /var/run/nginx.pid
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac

exit $RETVAL

设置可执行权限

[[email protected] ~]# chmod 755 /etc/init.d/nginx

添加开机启动

[[email protected] ~]# chkconfig --add nginx
[[email protected] ~]# chkconfig nginx on

开启

[[email protected] ~]# service nginx start
Starting Nginx:                                            [  OK  ]

停止

[[email protected] ~]# service nginx stop
Stopping Nginx:                                            [  OK  ]

重启

[[email protected] ~]# service nginx restart
Stopping Nginx:                                            [  OK  ]
Starting Nginx:                                            [  OK  ]

重新加载配置

[[email protected] ~]# service nginx reload
Reloading Nginx:                                           [  OK  ]

8、配置nginx服务器php解析

[[email protected] nginx-1.9.6]# vim /etc/nginx/nginx.conf
打开php配置:

65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }

user  nginx;
worker_processes  8;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  204800;
}

log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

access_log  /var/log/nginx/access.log  main;

sendfile        on;
    tcp_nopush     on;
    charset utf-8;

php-fpm启动报错

Starting php-fpm [18-Dec-2015 13:33:03] ERROR: unable to bind listening socket for address ‘127.0.0.1:9000‘: Address already in use (98)
[18-Dec-2015 13:33:03] ERROR: FPM initialization failed
 failed

[[email protected] nginx-1.9.6]# /usr/local/php/sbin/php-fpm -t
[18-Dec-2015 13:35:14] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful

[[email protected] nginx-1.9.6]# killall php-fpm
[[email protected] nginx-1.9.6]# service php-fpm start
Starting php-fpm  done

重新加载配置

[[email protected] nginx-1.9.6]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[[email protected] nginx-1.9.6]# nginx -s reload

测试php解析

[[email protected] nginx-1.9.6]# vim /usr/local/nginx/html/index.php

<?php
phpinfo();
?>

时间: 2025-01-09 20:05:45

1.8LNMP环境安装Nginx的相关文章

linux环境安装Nginx

在安装之前可以访问官网传送门 进行下载最新的源码包(centos/redhat). 安装还需要以下工具: yum -y install gcc gcc-c++ autoconf automake 模块依赖: yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel Nginx在linux环境下可以通过编译源码的方式来安装.最简单的安装命令如下: tar -zxvf nginx-1.x.xx.tar.gz cd ngi

阿里云 CentOS7.4 环境安装nginx

下载 nginx地址: http://nginx.org/en/download.html Mainline version可以理解为开发版本 Stable version 稳定版 Legacy version 历史遗留的稳定版 此处我选用了稳定版的 nginx-1.14.1 1.解压 将下载好的 nginx-1.14.1.tar.gz 存放在服务器的 /usr/nginx目录下 tar -zxvf nginx-1.14.1.tar.gz 2.进行configure配置 cd /usr/ngin

centos7 php开发环境安装-Nginx

1.Nginx编译安装 tar -zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2 ./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module

Nginx - Windows 环境安装 Nginx

1. 访问 http://nginx.org/en/download.html,下载 Windows 版本的安装包 2. 解压安装包,双击 nginx.exe,启动 nginx 3. 访问 http://localhost/,验证是否成功. 4. 其他操作: nginx.exe -s stop // 停止 nginx nginx.exe -s reload // 重新加载 nginx nginx.exe -s quit // 退出 nginx

开发人员学Linux(5):CentOS7编译安装Nginx并搭建Tomcat负载均衡环境

1.前言在上一篇讲述了JMeter的使用,在本篇就可以应用得上了.本篇将讲述如何编译安装Nginx并利用前面的介绍搭建一个负载均衡测试环境.2.软件准备Nginx-1.12.0,下载地址:https://nginx.org/download/nginx-1.12.0.tar.gzTomcat8(本系列已介绍过如何下载和安装)JMeter(本系列已介绍过如何下载和使用)注:VirtualBox宿主机IP为"192.168.60.16,虚拟机IP为:192.168.60.198,虚拟机通过桥接方式接

&#8203;Laml环境安装wordpress外加nginx负载均衡并实现phpmyadmin平滑升级!

Laml环境安装wordpress外加nginx负载均衡并实现phpmyadmin平滑升级 注意:我这里使用lamp搭建wordpress使用的全部都是rpm安装,如果有想要学习编译安装的朋友,可以参考另外一位午饭的博客,我安装wordpress也是参考他的内容,贴上他的地址: http://dreamfire.blog.51cto.com/418026/197595 操作系统全部使用centos6.6 注意:这里只列出了node3的配置过程,node2配置过程与node3完全一致!!! [[e

在CentOS上编译安装Nginx+实验环境搭建+测试

0.说明 Nginx作为一款优秀的Web Server软件同时也是一款优秀的负载均衡或前端反向代理.缓存服务软件,很有必要搭建实验环境来对其进行学习. 1.实验环境 本次实验的测试环境使用的宿主机操作系统为Windows 7,在Vmware虚拟机安装CentOS 6.5,说明如下: 宿主机操作系统Windows 7 虚拟机安装的操作系统CentOS 6.5 虚拟机操作系统上网方式NAT 而当使用NAT的方式进行上网时虚拟机.宿主机之间的网络连接关系可如下所示: 关于为什么网络拓扑结构是这样的,这

关于Nginx服务器搭建,编译源码安装Nginx的环境

如何选用web服务器: 静态业务:要求高并发,采用Nginx或者是ttpdligh 动态业务:采用Nginx和Apache Nginx的介绍: 他是俄罗斯人开发的,软件一共就780K,他本是是一款几台www软件,静态高并发,同时占用资源少,3万并发10个线程工占用150M. Nginx服务冲大的方面功能: www web服务   http 80 负载均衡     反向代理proxy web   cache(web缓存) Nginx的优点: 高并发(对于静态小文件) 占用资源少 功能种类比较多(w

CentOs上安装Nginx/Tomcat7/Mysql运行环境

这篇文章主要是面对初学者和创业公司,目的是在LINUX上安装一个真正能可用的TOMCAT的运行环境,可以作为商用服务器使用,该篇文章的版本会随时更新,保证真正可用. 文档版本:v1.0.0  作者:学涵  电子邮件: [email protected] 环境: Linux版本:CentOs (64位) JDK7版本:jdk-7u79-linux-x64 Tomcat版本:apache-tomcat-7.0.65 NGINX版本:yum安装 Mysql版本:yum安装5.6版本 1.安装JDK 7