Linux 下Nginx 的安装及负载均衡的简单配置
这次发布程序需要均衡负载,网上看了一下这方便的东西,觉得很不错,学完之后做下总结,一遍后期用到。
1、安装nginx之前需要安装的两个依赖,pcre-x.x.x.tar.gz 和pcre-devel-x.x.x.rpm这两个包(具体这两个有什么用处也没仔细研究过,不安装确实再安装nginx时失败)
1.1安装1.安装pcre-x.x.x.tar
tar zxvf pcre-x.x.x.tar.gz
cd pcre-x.x.x
./configure
make && make install
1.2.安装pcre-devel-x.x.x.rpm
rpm -ivh pcre-devel-x.x.x.rpm
2.安装nginx-x.x.x.tar.gz
tar zxvf nginx-x.x.x.tar.gz
cd nginx-x.x.x
./configure --with-http_stub_status_module --prefix=/usr/local/nginx --with-debug --with-http_sub_module
make && make install
3.安装完成后修改配置文件
vim /usr/local/nginx/conf/nginx.conf
修改后的配置文件如下
#user nobody;
user root;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; upstream Servers { server ip:port weight=;
server ip:port weight=; } server {
listen ;
server_name server www.btrcrm.com ; #charset koi8-r; #access_log logs/host.access.log main; location / {
proxy_pass http://Servers;
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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;
#}
}
}
配置完成后测试是否正常
/usr/local/nginx/sbin/nginx -t
接着启动nginx
/usr/local/nginx/sbin/nginx
若修改后配置文件或者将配置文件覆盖修改的 ,需要执行:
/usr/local/nginx/sbin/nginx -s reload
修改后需要重启nginx,发现重启不了端口被占用,则用一下命令解决
netstat grep --查看端口80占用 sudo fuser -k /tcp --关闭端口程序,然后重启即可
Linux 下Nginx 的安装及负载均衡的简单配置的更多相关文章
- Linux 下 nginx反向代理与负载均衡
前面几篇记录下nginx的基本运功,代理服务器的访问,这里来试验下nginx的反向代理. 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给 ...
- Linux下nginx+多个Tomcat负载均衡的实现
博主原创,转载请注明. 由于项目需要,共创建了10个Tomcat端,由nginx负责转发.9个Tomcat端口分别是8080,11000,12000,13000,14000,15000,16000,1 ...
- Linux下nginx编译安装教程和编译参数详解
这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...
- Linux系统——Nginx反向代理与负载均衡
集群集群是指一组(若干个)相互独立的计算机,利用高速通信网路组成的一个较大的计算机服务系统,每个集群节点(即集群中的每台计算机)都是运用各自服务的独立服务器.这些服务器之间可以彼此通信,协同向用户提供 ...
- nginx的安装和负载均衡例子(RHEL/CentOS7.4)
首先安装RHEL/CentOS7.4 mini ,然后关闭防火墙和 selinux ,更新系统(参看配置linux使用本地yum安装源和Redhat7/CentOS7 关闭防火墙和 selinux两个 ...
- linux下nginx的安装及配置
一.安装nginx前,我们首先要确保系统安装了g++.gcc.openssl-devel.pcre-devel和zlib-devel软件,可通过如图所示命令进行检测,如果以安装我们可以通过图二所示卸载 ...
- windows系统下nginx+tomcat+redis做负载均衡和session粘滞附整套解决方案
Nginx: 在nginx-1.8.0\conf目录下找到nginx.conf文件,打开文件修改文件中http{}中的内容,在http{}中加入 upstream localhost { serve ...
- Linux下Nginx的安装与配置
安装前需要安装pcre:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/1.解压缩: tar xjpf pcre-7.8.tar.b ...
- Linux下Nginx的安装、升级及动态添加模块
系统基于ubuntu server 14.04.4 amd64 安装 第一步 下载并解压Nginx压缩包 从Nginx官网下载Nginx,或者在Linux上执行wget http://nginx.or ...
随机推荐
- 20个很有用的CSS技巧
导语:下面这几个CSS技巧你可能不知道,1.彩色照片变黑白,2.所有元素垂直居中,3.禁用鼠标,4.模糊文字,小编学完能量满满的,觉得对CSS又充满了爱,你也来看看. 1. 黑白图像 这段代码会让你的 ...
- asp.net mvc放在iis7.5中提示404错误 js异步请求失效解决办法
asp.net mvc中js发请求一般写成: $.get("/Can/index"本地上是没有问题的但是部署到iis上,提示404,正确的请求的路径是:/网站名/Can/index ...
- Step one : 熟悉HTML
//H1 1 <html> <head> <title>BeiJing</title> </head> <body> <h ...
- CGI杂谈
CGI是一个连接外部应用程序到信息服务器(比如HTTP或者网络服务器)的标准.一个简单的HTML文档是无交互后台程序,它是静态的,也就是说它处于一个不可变的状态,即文本文件不可以变化.相反地,CGI程 ...
- [转]About the security content of iOS 8
Source:http://support.apple.com/kb/HT6441 For the protection of our customers, Apple does not disclo ...
- C语言变参函数的编写
1. 引言 一般我们编程的时候,函数中形式参数的数目通常是确定的,在调用时要依次给出与形式参数对应的实际参数.但在某些情况下我 们希望函数的参数个数可以根据需要确定,因此c语言引入可变参数函数.典型的 ...
- c语言,求字符数组的长度
练手代码,适用初级码农: #include<stdlib.h> #include<stdio.h> #include<assert.h> int count(con ...
- C# 从Excel2003将数据导入到SQL2005,数据发生截断的问题分析
C# 从Excel2003将数据导入到SQL2005,数据发生截断的问题分析 问题描述:大家没有遇到过这种情况使用自己编写的工具读取Excel2003文件中的数据,然后执行插入语句将数据批量导入到SQ ...
- iphone手机用wireshark抓包
ios连上电脑 查看udid. 启动虚拟接口 rvictl -s 7e65eeaa55a1e43dbdfb44a02f9871f1f304043e 打开mac权限 sudo chmod 644 /de ...
- webservice的调用方法
一.WebService在cs后台程序中的调用 A.通过命名空间和类名直接调用 示例: WebService ws = new WebService(); string s = ws.HelloWor ...