- wget http://nginx.org/download/nginx-1.2.0.tar.gz
2.tar zxvf nginx-1.2.0.tar.gz
3.cd nginx-1.2.0
4…/configure --with-stream
若出现error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
若出现error: the HTTP gzip module requires the zlib library
yum install -y zlib-devel
出现错误,一般都是少插件,yum install -y 即可
代理tcp,需要使用stream,所以这里要加–with-stream
5.make
6.make install
7.Nginx 默认安装到/usr/local/nginx
8.配置文件在 nginx.conf
8.cd /usr/local/nginx/sbin - 启动 ./nginx -c /usr/local/nginx/conf/nginx.conf
10.停止 ./nginx -s stop
11.重启 ./nginx -s reload
12.平滑重启 kill -HUP 主进程
13.从容的停止:kill -QUIT 主进程
14.快速停止:kill -TERM 主进程
15 ./nginx -t 检查配置文件 ./nginx -t -c /usr/local/nginx/conf/nginx.conf
配置文件配置
server {
listen 9000;
server_name www.hbzwfw.gov.cn;
#server_name 192.168.200.4;
#限制上传文件的大小
client_max_body_size 50m;
#charset koi8-r;
#access_log logs/host.access.log main;
#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 /default/newAj/ {
proxy_pass http://192.168.200.4:9001/newAj/;
}
location /default/fujian {
proxy_pass http://192.168.200.5:8000/;
}
location /default/ {
proxy_pass http://192.168.200.4:19000/default/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
#stream代理可以代理mysql端口转发
stream{
upstream socket_proxy{
server 193.168.237.8:9001;
}
server{
listen 9004;
proxy_pass socket_proxy;
}
}
//静态资源代理
location / {
autoindex on; #启用目录列表功能
autoindex_exact_size off; #显示出文件的确切大小,单位是bytes.改为off后,显示出文件的大概大小
autoindex_localtime on; #默认为off,显示的文件的GMT时间. 改为on后,显示的是文件的服务器时间
#root E:/layui/layui-master/;
root E:/layui/data/;
#root html;
index index.html index.htm;
}