#!/bin/bash
path=/opt/nginx
conf=/$path/conf
ver=http://nginx.org/download/nginx-1.10.2.tar.gz
wgetd=/usr/local/src
###########安装过程#############################
yum -y group install "Development Tools"
useradd -M -s /sbin/nologin nginx
yum -y install lsof wget zlib zlib-devel openssl openssl-devel pcre pcre-devel
if [[ -d $path ]]; then
echo "nginx is installed pls rm"
else
cd $wgetd
wget $ver
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
fi
if [[ $? == 0 ]]; then
echo "start configure"
fi
./configure \
--prefix=/opt/nginx \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6
if [[ $? == 0 ]]; then
echo "安装正常编译中"
make && make install
fi
cd $conf
mkdir -p conf.d
cp nginx.conf nginx.conf_$(date +%F)
cat << EOF >nginx.conf
user nginx nginx; ##用户名 用户组
worker_processes auto; ##对web提供服务时的进程数(根据系统配置定)
worker_rlimit_nofile 51200; ##worker打开文件数的限制 “too many open files”
error_log /opt/nginx/logs/nginx_error.log error; ##设置错误日志位置及等级debug, info, notice, warn, error, crit
pid /opt/nginx/logs/nginx.pid;
############events模块配置
events ##events模块中包含nginx中所有处理连接的设置
{
use epoll; ##复用客服端线程的轮询方法epoll or kqueue
worker_connections 2048; ##最大连接数
multi_accept on; ##接受尽可能多的连接
}
#############http模块配置(重要)#####################
http
{
include mime.types; ##文件扩展名与文件类型映射表
default_type application/octet-stream; ##默认文件类型
server_names_hash_bucket_size 128; ##服务器名字的hash表大小
client_header_buffer_size 1024k; ##上传文件大小
large_client_header_buffers 4 32k; ##客户请求header缓冲大小
client_max_body_size 50m; ##最大请求实体大小("Request Entity Too Large" (413)错误)
sendfile on; ##高效文件传输
tcp_nopush on; ##防止网络阻塞(数据包不会马上传输,有个等待时间)
keepalive_timeout 60; ##超时时间
tcp_nodelay on; ##禁用了Nagle 算法
###############nginx默认不支持php.java等
fastcgi_connect_timeout 300; ##fastcgi连接到后端的超时时间
fastcgi_send_timeout 300; ##fastcgi请求超时时间
fastcgi_read_timeout 300; ##fastcgi应答超时时间
fastcgi_buffer_size 64k; ##应答第一部分的缓冲区大小
fastcgi_buffers 4 64k; ##本地需要多大缓冲大小(4*64)
fastcgi_busy_buffers_size 128k; ##fastcgi_buffer_sized的2倍
fastcgi_temp_file_write_size 256k; ##写入缓存文件使用多大的数据块
gzip on;
gzip_min_length 1k; ##最小压缩文件大小
gzip_buffers 4 16k; ##压缩缓冲区
gzip_http_version 1.1; ##版本号
gzip_comp_level 2; ##压缩等级
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on; ##http的hader的加上一层vary的头部信息 判断是否需要压缩
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off; ##关闭nginx版本号显示
log_format main ##日志显示格式
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include conf.d/*.conf; ##包含conf.d/下面的配置(server主机信息,upstream,等 个人习惯这些都分开放一个文件夹)
}
EOF
############################################web.conf
cat << EOF >conf.d/web.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index 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 html;
}
# 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 /scripts$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;
#}
}
EOF
ln -s $path/sbin/nginx /usr/local/sbin/nginx
nginx
lsof -i:80
nginx安装配置脚本
最新推荐文章于 2023-06-28 21:33:02 发布