日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

linux安装nginx1.9,CentOS7.2安装Nginx 1.9

發(fā)布時間:2023/12/15 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux安装nginx1.9,CentOS7.2安装Nginx 1.9 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

今天在最新的centos7.2上安裝nginx1.9,希望安裝流程對你有所幫助,一定要查看對應(yīng)centos的版本。

一、確認一下centos的版本

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

二、安裝依賴包和開發(fā)工具:

yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33

成功返回:

Transaction Summary

================================================================================

Install 91 Packages (+45 Dependent packages)

Upgrade 9 Packages (+19 Dependent packages)

Total size: 202 M

Total download size: 178 M

三、清除系統(tǒng)中的httpd痕跡

yum remove httpd

rm -rvf /etc/httpd

rm /usr/bin/pod2man

四、創(chuàng)建www用戶和用戶組:

groupadd www

useradd -s /sbin/nologin -g www www

五、解壓nginx模塊包:

tar zxvf zlib-1.2.8.tar.gz -C /usr/src

tar zxvf pcre-8.12.tar.gz -C /usr/src

tar zxvf openssl-1.0.1.tar.gz -C /usr/src

六、解壓、配置、編譯、安裝nginx1.9:

tar zxvf nginx-1.9.0.tar.gz -C /usr/src/

cd /usr/src/nginx-1.9.0/

./configure --prefix=/usr/local/nginx \

--user=www \

--group=www \

--sbin-path=/usr/local/nginx/sbin/nginx \

--conf-path=/usr/local/nginx/conf/nginx.conf \

--error-log-path=/home/www/log/error.log \

--http-log-path=/home/www/log/access.log \

--pid-path=/home/www/pid/nginx.pid \

--lock-path=/home/www/pid/nginx.lock \

--with-mail \

--with-file-aio \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_dav_module \

--with-http_sub_module \

--with-http_spdy_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_stub_status_module \

--with-zlib=/usr/src/zlib-1.2.8 \

--with-pcre=/usr/src/pcre-8.12 \

--with-openssl=/usr/src/openssl-1.0.1 \

--without-select_module \

--without-poll_module \

--http-client-body-temp-path=/tmp/clientbody \

--http-proxy-temp-path=/tmp/proxy \

--http-fastcgi-temp-path=/tmp/fastcgi \

--http-uwsgi-temp-path=/tmp/uwsgi \

--http-scgi-temp-path=/tmp/scgi

make

make install

七、編輯nginx.conf配置文件:

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx.conf

vim /etc/nginx.conf

user www www;

worker_processes auto;

pid /home/www/pid/nginx.pid;

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

multi_accept on;

}

http

{

include mime.types;

default_type application/octet-stream;

charset UTF-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;

client_body_buffer_size 128k;

sendfile on;

tcp_nopush on;

keepalive_timeout 45;

server_tokens off;

tcp_nodelay on;

# Proxy

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header REMOTE-HOST $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Fastcgi

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 256k;

# Gzip Compression

gzip on;

gzip_buffers 16 8k;

gzip_comp_level 2;

gzip_http_version 1.1;

gzip_min_length 256;

gzip_proxied any;

gzip_vary on;

gzip_types

# MIME Type

text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml

text/javascript application/javascript application/x-javascript

text/x-json application/json application/x-web-app-manifest+json

text/css text/plain text/x-component

font/opentype application/x-font-ttf application/vnd.ms-fontobject

image/x-icon;

gzip_disable "msie6";

# Cache

open_file_cache max=51200 inactive=20s;

open_file_cache_valid 30s;

open_file_cache_min_uses 1;

open_file_cache_errors on;

# Log Format

log_format access '[$time_iso8601] "$remote_addr" "$http_x_forwarded_for"'

'"$request" "$request_body" "$http_cookie"'

'"$upstream_addr" "$upstream_status"'

'"$http_referer" "$status"'

'"$body_bytes_sent" "$http_user_agent"';

################################################## default ##################################################

server

{

listen 80 default;

server_name 127.0.0.1;

access_log /home/www/log/access.log access;

error_log /home/www/log/error.log error;

root /home/www/html/;

index index.html index.htm index.php;

location ~ [^/]\.php(/|$)

{

fastcgi_pass unix:/dev/shm/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

}

location /nginx_status

{

stub_status on;

access_log off;

allow 127.0.0.1;

deny all;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$

{

expires 30d;

access_log off;

}

location ~ .*\.(js|css)?$

{

expires 7d;

access_log off;

}

if (!-e $request_filename)

{

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

}

################################################## vhost ##################################################

include vhost/*.conf;

}

復(fù)制代碼

八、創(chuàng)建nginx相關(guān)目錄,并修改權(quán)限:

mkdir -p /home/www/html

chown -R www:www /home/www/

九、測試啟動nginx服務(wù):

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

nginx -t

nginx -c /usr/local/nginx/conf/nginx.conf

ps -aux | grep nginx

netstat -anptu | grep 80

十、編寫nginx啟動腳本:

vim /etc/init.d/nginx

#!/bin/sh

# chkconfig: 2345 80 20

# Description: Start and Stop Nginx

# Provides: nginx

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=nginx

NGINX_BIN=/usr/local/nginx/sbin/$NAME

CONFIGFILE=/usr/local/nginx/conf/$NAME.conf

PIDFILE=/home/www/pid/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

case "$1" in

start)

echo -n "Starting $NAME... "

if netstat -tnpl | grep -q nginx;then

echo "$NAME (pid `pidof $NAME`) already running."

exit 1

fi

$NGINX_BIN -c $CONFIGFILE

if [ "$?" != 0 ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

stop)

echo -n "Stoping $NAME... "

if ! netstat -tnpl | grep -q nginx; then

echo "$NAME is not running."

exit 1

fi

$NGINX_BIN -s stop

if [ "$?" != 0 ] ; then

echo " failed. Use force-quit"

exit 1

else

echo " done"

fi

;;

status)

if netstat -tnpl | grep -q nginx; then

PID=`pidof nginx`

echo "$NAME (pid $PID) is running..."

else

echo "$NAME is stopped"

exit 0

fi

;;

force-quit)

echo -n "Terminating $NAME... "

if ! netstat -tnpl | grep -q nginx; then

echo "$NAME is not running."

exit 1

fi

kill `pidof $NAME`

if [ "$?" != 0 ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

restart)

$SCRIPTNAME stop

sleep 1

$SCRIPTNAME start

;;

reload)

echo -n "Reload service $NAME... "

if netstat -tnpl | grep -q nginx; then

$NGINX_BIN -s reload

echo " done"

else

echo "$NAME is not running, can't reload."

exit 1

fi

;;

configtest)

echo -n "Test $NAME configure files... "

$NGINX_BIN -t

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"

exit 1

;;

esac

十一、添加nginx系統(tǒng)服務(wù):

chmod a+x /etc/init.d/nginx

chkconfig --add nginx

chkconfig --level 2345 nginx on

chkconfig --list | grep nginx

十二、重新啟動nginx服務(wù):

service nginx restart

ps -aux | grep nginx

netstat -anptu | grep 80

十三、測試:

vim /home/www/html/index.html

This is test nginx!!!

nginx server test is ok!!!

chown www:www /home/www/html/index.html

十四、防火墻開啟80端口:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

總結(jié)

以上是生活随笔為你收集整理的linux安装nginx1.9,CentOS7.2安装Nginx 1.9的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。