Nginx服务器(负载均衡)
来源:互联网 发布:深圳聚宝网络 编辑:程序博客网 时间:2024/06/10 01:18
1.首先创建个文件
vi /etc/yum.repos.d/nginx.repo
2.复制下面文本,保存并退出
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
3.运行以下命令进行安装
#yum install pcre 安装依赖包
#yum install nginx
4.创建日子文件
vi /etc/nginx/logs/status.log
5.配置nginx.conf文件
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}
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 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.17bibi.com;
charset utf-8;
index index.html index.htm index.jsp login.jsp;
#access_log logs/host.access.log main;
root /var/www/shop;
location /
{
index index.jsp;
proxy_pass http://localhost:7001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|html)$
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location ~.*\.(js|css)?$
{
expires 1h;
}
location ~(favicon.ico)
{
log_not_found off;
expires 30d;
break;
}
location /status
{
access_log /etc/nginx/logs/status.log;
auth_basic "NginxStatus";
allow 10.0.209.0/24;
deny all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /etc/nginx/vhosts/*;
}
5.启动nginx
启动:service nginx start
启动:service nginx start
停止:service nginx stop
重启:service nginx reconfigure
查看状态:service nginx status
6.配置多个子域名
在配置文件最后面加上配置指向
include /usr/local/nginx/conf/vhosts/*;
#vi /usr/local/nginx/conf/vhosts/test.17bibi.com.conf
子域名的配置
server {
listen 80;
server_name test.17bibi.com;
charset utf-8;
index index.html index.htm index.jsp login.jsp;
#access_log logs/host.access.log main;
root /var/www/shop2/;
location /
{
index index.jsp;
proxy_pass http://localhost:7070;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|html)$
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location ~.*\.(js|css)?$
{
expires 1h;
}
location ~(favicon.ico)
{
log_not_found off;
expires 30d;
break;
}
location /status
{
access_log /usr/local/nginx/logs/status.log;
auth_basic "NginxStatus";
allow 10.0.209.0/24;
deny all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
0 0
- Nginx服务器(负载均衡)
- Nginx 负载均衡服务器
- Nginx负载均衡服务器配置(Linux)
- 负载均衡服务器nginx安装
- nginx服务器负载均衡配置
- nginx服务器搭建负载均衡
- nginx高负载均衡服务器
- nginx架构(二)Nginx服务器实现负载均衡配置
- nginx简单搭建负载均衡服务器(windows)
- Nginx负载均衡服务器配置**(学习一笔记)
- 服务器数据库系列 - Nginx 负载均衡配置
- 服务器数据库系列 - 解析nginx负载均衡
- Nginx+tomcat负载均衡缓存服务器集群
- 使用 Nginx 创建服务器的负载均衡
- 利用Nginx构建负载均衡服务器
- 利用Nginx构建负载均衡服务器
- Nginx+Tomcat服务器负载均衡实践方案
- 利用Nginx构建负载均衡服务器
- 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
- 哥伦布k阶编解码
- Android 在自定义view中动态设置布局规则
- Docker Swarm与Apache Mesos的区别
- express设置ejs渲染.html文件
- Nginx服务器(负载均衡)
- Linux中profile、bashrc、bash_profile之间的区别和联系
- 关于守护进程daemon
- 安卓中图像处理(收集)
- MFC 文件打开和保存对话框
- 单点登陆script传值
- java main函数的args[]参数
- 配置文件报错:不允许有匹配 "[xX][mM][lL]" 的处理指令目标。
- Yarn的原理与资源调度