码迷,mamicode.com
首页 > 其他好文 > 详细

nginx安装配置

时间:2017-08-22 00:24:31      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:nginx安装和配置

源码安装
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
# tar xf pcre-8.36.tar.bz2 
# cd pcre-8.36
# ./configure 
# make
# make install
或者yum安装
# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel pcre pcre-devel openssl bzip2-devel libxml2 libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel openssl-devel libevent libevent-devel
(2)安装Nginx
首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -r nginx
# useradd -r -g nginx -s /sbin/nologin nginx

接着开始编译和安装:
# wget http://nginx.org/download/nginx-1.10.1.tar.gz
# tar xf nginx-1.10.1.tar.gz
# cd nginx-1.10.1  
# ./configure   --prefix=/usr/local/nginx   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_flv_module   --with-file-aio   --with-http_stub_status_module   --with-http_gzip_static_module   --with-pcre   --with-stream --with-http_v2_module   --with-http_mp4_module
# make && make install

参考配置文件:
# cat nginx.conf
user  nginx;
worker_processes  8;
worker_rlimit_nofile 102400;

error_log  /data0/log/nginx/error.log  notice;

pid        /data0/log/nginx/nginx.pid;


events {
    use epoll;
    worker_connections  65535;
}


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

    log_format  nginx_log  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    client_header_timeout 30s;
    client_body_timeout 30s;
    send_timeout 60s;    

    client_max_body_size 350m;
    sendfile        on;
    keepalive_timeout  65;
    proxy_buffers 8 128k;
    proxy_buffer_size 128k;
    gzip  on;
    server {
        listen 80 default_server;
        server_name _;
        return 404;
    }

include vhosts/*.conf;
}


虚拟主机配置参考:
# cat domain.conf
upstream hall.tg-game.cn {
	server 10.192.23.204:8080 max_fails=3 fail_timeout=30s;
    server 10.192.23.221:8080 max_fails=3 fail_timeout=30s;
        ip_hash;

}

server {
	listen 80;
	server_name hall.tg-game.cn;
	location / {
		root html;
		index index.html index.htm;
		proxy_pass http://hall.tg-game.cn/;
                proxy_set_header  X-Real-IP        $remote_addr;
                proxy_set_header  Host             $host;
                proxy_set_header  REMOTE-HOST      $remote_addr;
                proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
                client_max_body_size 512k;
		access_log  /data0/log/nginx/hall.tg-game.cn.log nginx_log;
         #       allow 101.254.183.162;
         #       deny all;

	}
}


脚本安装:
#!/bin/bash
#
# Install_Nginx.sh
# 

#yum install  pcre openssl#
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel pcre pcre-devel openssl bzip2-devel libxml2 libxml2-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel openssl-devel libevent libevent-devel 2>/tmp/yum.log 1>/dev/null || exit 6

#add nginx#
groupadd -r nginx  | echo "group ‘nginx‘ already exists" 
useradd -r -g nginx -s /sbin/nologin nginx || echo "user  ‘nginx‘ already exists"

#install nginx#
cd /usr/local/src/ 
wget http://nginx.org/download/nginx-1.10.1.tar.gz 2>/tmp/down_nginx.log 1>/dev/null && echo "download success" || exit 6
tar xf nginx-1.10.1.tar.gz 
cd nginx-1.10.1
./configure   --prefix=/usr/local/nginx   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_flv_module   --with-file-aio   --with-http_stub_status_module   --with-http_gzip_static_module   --with-pcre   --with-stream --with-http_v2_module  --with-http_mp4_module 2>/tmp/nginx_config.log 1>/dev/null
if [ $? != 0 ];then
   echo "./configure false" 
   exit 3
fi

make 2>/tmp/nginx_make.log 1>/dev/null
if [ $? != 0 ];then
   echo "make false" 
   exit 3
fi 
make install 2>/tmp/nginx_make_install.log 1>/dev/null
if [ $? != 0 ];then
   echo "make install false" 
   exit 3
else
   echo "Install_Nginx success"
   cd /tmp && rm -rf yum.log nginx_config.log nginx_make.log nginx_make_install.log down_nginx.log
fi


nginx安装配置

标签:nginx安装和配置

原文地址:http://wupengfei.blog.51cto.com/7174803/1958133

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!