安裝必備工具
$ 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模塊,傳輸數(shù)據(jù)打包,省流量(但消耗資源)。 openssl:提供ssl加密協(xié)議。
安裝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
配置環(huán)境變量
[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有可執(zhí)行權限,一般linux默認是不會給rc.local可執(zhí)行權限的
方式二:將nginx加入服務(我選擇這個)
1、在/etc/?rc.d/init.d/下面增加一個腳本,名稱 nginx,腳本內容<a >查看這里</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、加入系統(tǒng)服務并開機自啟動
chmod +x /etc/rc.d/init.d/nginx (設置可執(zhí)行權限)
chkconfig --add nginx (添加系統(tǒng)服務)
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錯誤日志的辦法