PHP实战PHP经验分享

CentOS7.6安装nginx1.16.0

2019-08-07  本文已影响10人  路上阳光

安装必备工具

$ yum -y install gcc gcc-c++ autoconf automake

$ yum -y install zlib zlib-devel openssl openssl-devel pcre-devel gd-devel

说明:

pcre: 用来作地址重写的功能。 zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。 openssl:提供ssl加密协议。

安装pcre

​[root@localhost src] wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gz
​[root@localhost src]# tar -zxf pcre-8.43.tar.gz
​[root@localhost src]# cd pcre-8.43
​[root@localhost pcre-8.40]# ./configure --prefix=/usr/local/pcre
​[root@localhost pcre-8.40]# make && make install

安装zlib

​[root@localhost src]# wget http://zlib.net/zlib-1.2.11.tar.gz
​[root@localhost src]# tar -zxf zlib-1.2.11.tar.gz
​[root@localhost src]# cd zlib-1.2.11
​[root@localhost zlib-1.2.11]# ./configure --prefix=/usr/local/zlib
​[root@localhost zlib-1.2.11]# make && make install

安装openssl

​[root@localhost src]# wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
​[root@localhost src]# tar -zxf openssl-1.1.1c.tar.gz
​[root@localhost src]# cd openssl-1.1.1c
​[root@localhost openssl-1.1.1c]# ./config --prefix=/usr/local/openssl
​[root@localhost openssl-1.1.1c]# make && make install
​[root@localhost openssl-1.1.1c]# export PATH=$PATH:/usr/local/openssl/bin
​[root@localhost openssl-1.1.1c]# source /etc/profile

安装Nginx

安装

[root@localhost src]# wget http://nginx.org/download/nginx-1.16.0.tar.gz
[root@localhost src]# tar -zxf nginx-1.16.0.tar.gz
[root@localhost src]# cd nginx-1.16.0
[root@localhost src]# groupadd nginx
[root@localhost src]# useradd -g nginx -s /bin/false nginx

配置

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_secure_link_module \
--with-mail \
--with-mail_ssl_module \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.1c

可以查看编译选项

./configure --help

编译安装

[root@localhost nginx-1.15.12]# make && make install

配置环境变量

[root@localhost nginx-1.15.12]# vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin:/usr/local/php/bin
[root@localhost nginx-1.15.12]# source /etc/profile

自启动

方式一:加入到/etc/rd.d/rc.local文件末尾

将/usr/local/nginx/sbin/nginx加入到rc.local文件末尾,请确保rc.local有可执行权限,一般linux默认是不会给rc.local可执行权限的

方式二:将nginx加入服务(我选择这个)

1、在/etc/​rc.d/init.d/下面增加一个脚本,名称 nginx,脚本内容<a href="https://my.oschina.net/tomener/blog/664469">查看这里</a>

#! /bin/bash
# chkconfig: 35 85 15  
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
    $DAEMON || echo -n " already running"
}
d_stop() {
    $DAEMON -s quit || echo -n " not running"
}
d_reload() {
    $DAEMON -s reload || echo -n " counld not reload"
}
case "$1" in
start)
    echo -n "Starting $DESC:$NAME"
    d_start
    echo "."
;;
stop)
    echo -n "Stopping $DESC:$NAME"
    d_stop
    echo "."
;;
reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
    echo "reloaded."
;;
restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    sleep 2
    d_start
    echo "."
;;
*)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
;;
esac
exit 0

2、加入系统服务并开机自启动

chmod +x /etc/rc.d/init.d/nginx (设置可执行权限)

chkconfig --add nginx (添加系统服务)

chkconfig --level 35 nginx on (开机自启动)

3、相关操作

1、启动 service nginx start
2、停止 service nginx stop
3、重启 service nginx restart
4、重载配置 service nginx reload

配置文件

/usr/local/nginx/conf

user  nginx nginx;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    use epoll;
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #隐藏版本号
    server_tokens off;

    gzip  on;

    client_max_body_size 5m;

    #设置404
    fastcgi_intercept_errors on;
    
    include vhost/*.conf;
}

相关推荐

http://www.ttlsa.com/nginx/use-nginx-proxy/
解决nginx下php-fpm不记录php错误日志的办法

上一篇下一篇

猜你喜欢

热点阅读