歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> centos6.5安裝nginx-1.8.0,nginx-1.8.0

centos6.5安裝nginx-1.8.0,nginx-1.8.0

日期:2017/3/3 17:42:40   编辑:學習Linux

centos6.5安裝nginx-1.8.0,nginx-1.8.0

centos6.5安裝nginx-1.8.0,nginx-1.8.0


1.Nginx安裝環境:

  gcc: 安裝nginx需要先將官網下載的源碼進行編譯,編譯依賴gcc環境,如果沒有gcc環境,需要安裝gcc:yum install gcc-c++

  pcre:PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx的http模塊使用pcre來解析正則表達式,所以需要在linux上安裝pcre庫。yum install -y pcre pcre-devel (注:pcre-devel是使用pcre開發的一個二次開發庫。nginx也需要此庫。)

  zlib:zlib庫提供了很多種壓縮和解壓縮的方式,nginx使用zlib對http包的內容進行gzip,所以需要在linux上安裝zlib庫。yum install -y zlib zlib-devel

  openssl:OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用。nginx不僅支持http協議,還支持https(即在ssl協議上傳輸http),所以需要在linux安裝openssl庫。yum install -y openssl openssl-devel

2.清除系統中的httpd痕跡:
  yum remove httpd
  rm -rvf /etc/httpd

3.創建www用戶和用戶組:
groupadd www
useradd -s /sbin/nologin -g www www

5.解壓、配置、編譯、安裝nginx:
tar zxvf nginx-1.8.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.8.0/
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-mail \
--with-mail_ssl_module \
--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_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
make && make install

6.編輯nginx.conf配置文件:
vim /usr/local/nginx/conf/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;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;

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 on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";

server_tokens off;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
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;
index index.html index.htm index.php;
root /home/www/html/;
error_page 404 /404.html;

location ~ [^/]\.php(/|$)
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
}
include vhost/*.conf;
}
7.創建目錄並修改權限:
mkdir -p /home/www/log
mkdir -p /home/www/pid
mkdir -p /home/www/html
chown -R www:www /home/www/log
chown -R www:www /home/www/pid
chown -R www:www /home/www/html
chown -R www:www /usr/local/nginx

8.測試啟動Nginx

./nginx

9.創建測試頁面和錯誤頁面,並賦予權限:
touch /home/www/html/index.html
cat>/home/www/html/index.html<<EOF
This is the test Page for Nginx !!!
EOF
touch /home/www/html/404.html
cat>/home/www/html/404.html<<EOF
Error Page for Nginx !!!
EOF
chown -R www:www /home/www/html

10.測試:
http://localhost/
http://localhost/error

11.防火牆開啟80端口:

vim /etc/sysconfig/iptablse.conf
添加 -A INPUT -p tcp --dport 80 -j ACCEPT

12.重啟防火牆

service iptables restart

http://xxxxxx/Linuxjc/1184870.html TechArticle

Copyright © Linux教程網 All Rights Reserved