nginx安装配置

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
源码安装
# 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









本文转自 wpf926 51CTO博客,原文链接:http://blog.51cto.com/wupengfei/1958133,如需转载请自行联系原作者
目录
相关文章
|
18天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
43 2
|
23天前
|
应用服务中间件 nginx
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
|
18天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
52 0
|
18天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
24 0
|
18天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
48 0
|
2天前
|
应用服务中间件 nginx
nginx配置集群轮训策略
nginx配置集群轮训策略
10 0
|
3天前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
4天前
|
应用服务中间件 nginx Docker
docker安装nginx
`docker search`找镜像,`pull`下载,后台 `-d` 运行容器,命名 `--name`,映射端口 `-p`。本机测试,确保服务器安全组开放端口,公网通过`http://ip:port`访问。用`docker stop id`停止容器。[查看详情](https://blog.csdn.net/javayoungcoolboy/article/details/134976510)
|
4天前
|
应用服务中间件 网络安全 nginx
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
|
7天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
19 3