CentOS7.3インストールNginx 1をコンパイルする.10.1
コンパイル環境のインストール
yum -y gcc
yum -y gcc++
yum -y gcc-c++
yum -y install wget
インストールファイルをダウンロードして解凍
>
mkdir soft && cd soft
> pcre,openssl,zlib
wget -c http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
wget -c https://www.openssl.org/source/openssl-1.0.2l.tar.gz
wget -c http://zlib.net/zlib-1.2.11.tar.gz
> nginx
wget -c http://nginx.org/download/nginx-1.10.1.tar.gz
>
tar -zxvf pcre-8.39.tar.gz
tar -zxvf openssl-1.0.2l.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf nginx-1.10.1.tar.gz
ユーザーとディレクトリの作成
> nginx
useradd -r nginx -s /sbin/nologin -M
> nginx
mkdir -p /var/tmp/nginx/{client_body,proxy,fastcgi,uwsgi,scgi}
>
chown -R nginx /var/tmp/nginx
コンパイルnginx-1.10.1
cd ~/soft/nginx-1.10.1
./configure \
--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 \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre=../pcre-8.39 \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.0.2l \
--with-debug \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-stream
make && make install
サービススクリプトファイルの編集
>
vim /etc/init.d/nginx
>
#! /bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
#
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock
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
sleep 1
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
nginx起動スクリプトの構成
>
chmod +x /etc/init.d/nginx
>
chkconfig --add nginx
>
chkconfig nginx on
nginxサーバの起動
systemctl start nginx
サービス開始ステータス
[root@localhost soft]# systemctl status nginx.service
● nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (running) since Tue 2017-06-13 11:47:44 EDT; 22s ago
Docs: man:systemd-sysv-generator(8)
Process: 40801 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
Main PID: 40808 (nginx)
Memory: 1.0M
CGroup: /system.slice/nginx.service
├─40808 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─40809 nginx: worker process
Jun 13 11:47:43 localhost.localdomain systemd[1]: Starting SYSV: Nginx is an HTTP(S) server,
HTTP(S) reverse proxy and IMAP/POP3 proxy server...
Jun 13 11:47:44 localhost.localdomain nginx[40801]: Starting nginx: [ OK ]
Jun 13 11:47:44 localhost.localdomain systemd[1]: Started SYSV: Nginx is an HTTP(S) server,
HTTP(S) reverse proxy and IMAP/POP3 proxy server.
[root@localhost soft]#
nginxプロファイルの変更
#
#user nobody;
# , cpu
worker_processes 1;
# PID
#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;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]";
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
server {
listen 80;
server_name www.nginx.dev;
#charset koi8-r;
access_log logs/nginx.dev.access.log main;
location / {
root /data/www/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/www/html;
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
CentOS 7オープン80 TCPポートを追加
>
firewall-cmd --zone=public --add-port=80/tcp --permanent
--zone=public
--add-port=80/tcp
--permanent
> ( root , , , . )
firewall-cmd --reload
本文があなたの仕事と勉強に役立つことを望んでいます.
悪くないと思ったらどうやって感謝しますか?お母さん!いいね!
Good Luck! from warnerwu at 2017.06.24 PM