设为首页 收藏本站
查看: 1426|回复: 0

LNMP环境安装Nginx

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-12-23 08:55:58 | 显示全部楼层 |阅读模式
Nginx服务器安装和配置

1、安装pcre软件包
[iyunv@www ~]# rpm -qa | grep pcre
[iyunv@www ~]# yum -y install pcre


2、创建nginx用户
[iyunv@www ~]# useradd -s /sbin/nologin nginx
[iyunv@www ~]# 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

[iyunv@www 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

[iyunv@www nginx-1.9.6]# make && make install

[iyunv@www nginx-1.9.6]# ls /usr/local/nginx/
html

检查配置

[iyunv@www 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
[iyunv@www nginx-1.9.6]# mkdir /tmp/nginx/client_body -p
[iyunv@www 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

[iyunv@www nginx-1.9.6]# nginx
[iyunv@www 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版本及编译参数
[iyunv@www 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启动脚本
[iyunv@www ~]# 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


设置可执行权限

[iyunv@www ~]# chmod 755 /etc/init.d/nginx

添加开机启动

[iyunv@www ~]# chkconfig --add nginx
[iyunv@www ~]# chkconfig nginx on


开启
[iyunv@www ~]# service nginx start
Starting Nginx:                                            [  OK  ]


停止
[iyunv@www ~]# service nginx stop
Stopping Nginx:                                            [  OK  ]


重启
[iyunv@www ~]# service nginx restart
Stopping Nginx:                                            [  OK  ]
Starting Nginx:                                            [  OK  ]

重新加载配置

[iyunv@www ~]# service nginx reload
Reloading Nginx:                                           [  OK  ]




8、配置nginx服务器php解析
[iyunv@www 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;

wKiom1Z5TM-iS_xQAAB0MHM1BR4922.jpg
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


[iyunv@www 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

[iyunv@www nginx-1.9.6]# killall php-fpm
[iyunv@www nginx-1.9.6]# service php-fpm start
Starting php-fpm  done


重新加载配置

[iyunv@www 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

[iyunv@www nginx-1.9.6]# nginx -s reload

测试php解析
[iyunv@www nginx-1.9.6]# vim /usr/local/nginx/html/index.php

<?php
phpinfo();
?>

wKioL1Z5Us-w4n_RAAFOnfSzyw4757.jpg



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-155004-1-1.html 上篇帖子: LAMP环境下不能解析php原因及排查步骤 下篇帖子: 安装lamp
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表