nginx为反向代理服务器,可以反向代理不同域名转向不同的具体服务器。可以用于负载压力或是同一台机器使用不同域名进行访问。

以下片段是服务器配置:

 #user cmcc;

 worker_processes 16;
#worker_cpu_affinity 00000001 00000010 00000100 00001000;
worker_cpu_affinity 0000000000000001 0000000000000010 0000000000000100 0000000000001000 0000000000010000 0000000000100000 0000000001000000 0000000010000000 0000000100000000 0000001000000000 0000010000000000 0000100000000000 0001000000000000 00100000000000000000 0100000000000000 1000000000000000;
#pid /var/run/nginx.pid;
#error_log /var/log/nginx/error_log error;
worker_rlimit_nofile 655350;
events {
use epoll;
worker_connections 655350;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /tmp/access.log;
error_log /tmp/error.log;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 4k;
client_max_body_size 10m;
open_file_cache max=655350 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
sendfile on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/cssapplication/xml;
gzip_vary on; include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; #proxy server
upstream webvoc.com{
server 115.28.213.130:8080 weight=2;
}
upstream www.webvoc.com{
server 115.28.213.130:8080 weight=2;
}
#upstream tomcat_stat {
# server 111.13.47.186:8080 weight=3;
#} #visual master_server
server {
listen 8011;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root /usr/local/www;
index index.php;
} location /svn {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8099/svn/;
}
#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 /usr/local/www;
} # 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 /usr/local/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}
server{
listen 80;
server_name webvoc.com;
error_log /tmp/vm_err.log;
access_log /tmp/vm_access.log;
location /{
proxy_pass http://webvoc.com;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_headers_hash_bucket_size 128;
proxy_temp_file_write_size 128k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .(qqLogin|registerQQ|registerWeiBo).action$ {
proxy_pass http://webvoc.com;
} location ~ .(oauth2_qq).jsp$ {
proxy_pass http://webvoc.com;
} error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root /usr/share/nginx/www;
} #location /NginxStatus { # stub_status on;
# access_log off;
# auth_basic "NginxStatus";
#} location ~* \.(gif|jpg|jpeg|questionStyle|kindeditor|fileupload)$ { proxy_pass http://webvoc.com;
} }
server{
listen 80;
server_name www.webvoc.com;
error_log /tmp/vm_err.log;
access_log /tmp/vm_access.log;
location /{
proxy_pass http://www.webvoc.com;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_headers_hash_bucket_size 128;
proxy_temp_file_write_size 128k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .(qqLogin|registerQQ|registerWeiBo).action$ {
proxy_pass http://webvoc.com;
} location ~ .(oauth2_qq).jsp$ {
proxy_pass http://www.webvoc.com;
} error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root /usr/share/nginx/www;
} #location /NginxStatus { # stub_status on;
# access_log off;
# auth_basic "NginxStatus";
#} location ~* \.(gif|jpg|jpeg|questionStyle|kindeditor|fileupload)$ { proxy_pass http://www.webvoc.com;
} }
}

#proxy server 在这里配置一个代理名称,最重要的是server指向的地址。

如下:

upstream webvoc.com{
  server 115.28.213.130:8080 weight=2;
 }

名称为webvoc.com的域名指向了115.28.213.130:8080的实际地址。

weight=2向的反向代理权重,当多个负载服务器工作时,可以加大转向某个服务器的机率。

upstream www.webvoc.com{
  server 115.28.213.130:8080 weight=2;
 }

表明使用www.webvoc.com指向同一个网站。

     server{
listen 80;
server_name webvoc.com;
error_log /tmp/vm_err.log;
access_log /tmp/vm_access.log;
location /{
proxy_pass http://webvoc.com;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_headers_hash_bucket_size 128;
proxy_temp_file_write_size 128k;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .(qqLogin|registerQQ|registerWeiBo).action$ {
proxy_pass http://webvoc.com;
} location ~ .(oauth2_qq).jsp$ {
proxy_pass http://webvoc.com;
} error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root /usr/share/nginx/www;
} #location /NginxStatus { # stub_status on;
# access_log off;
# auth_basic "NginxStatus";
#} location ~* \.(gif|jpg|jpeg|questionStyle|kindeditor|fileupload)$ { proxy_pass http://webvoc.com;
} }

server:是一个完整的服务器转向规则说明:

listen:是要侦听的端口号,如果使用域名访问,这里可全部设置为80端口。

server_name:这个就是上面提到upstream后面的名字。一般情况下和域名相同,但是可以不一致。

这个nginx配置中,有一个站点为PHP站点,直接使用nginx作解析。配置代码如下:

 server {
listen 8011;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root /usr/local/www;
index index.php;
} location /svn {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8099/svn/;
}
#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 /usr/local/www;
} # 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 /usr/local/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
#}
}

nginx的使用配置的更多相关文章

  1. nginx + SSL优化配置

    nginx + SSL优化配置: #http段添加如下配置项: http { ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户 ...

  2. nginx安装与配置

    一.在线安装 ubuntu 安装 sudo apt-get install nginx 安装后文件结构为: 配置文件:/etc/nginx ,并且每台虚拟主机已经安排在 /etc/nginx/site ...

  3. windows下nginx安装、配置与使用(转载)

    目前国内各大门户网站已经部署了Nginx,如新浪.网易.腾讯等:国内几个重要的视频分享网站也部署了Nginx,如六房间.酷6等.新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx ...

  4. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  5. nginx入门篇----nginx服务器基础配置

    1.nginx.conf文件结构...                         #全局块  events{  ...  }  http                      #http块{ ...

  6. 高流量站点NGINX与PHP-fpm配置优化(译)

    使用Nginx搭配PHP已有7年的这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置. 以下正是这方面的一些提示和建议: 1. 将TCP切换为UNIX域套接字 UNIX域套接字相比T ...

  7. nginx反向代理配置及优化

    nginx反向代理配置及优化前言: 由于服务器apache抗不住目前的并发.加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反 ...

  8. LVS + Keepalived + Nginx安装及配置

    1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...

  9. windows下nginx+php简单配置

    Nginx+php运行环境搭建 虽然目前nginx使用很广泛,在大陆主流的互联网站点或多或少会用到这个俄国人开发的小应用(占用资源小).但是我这个土鳖还是第一次自己独立配置,网上资料不少,但是还是遇到 ...

  10. nginx虚拟主机配置

    nginx虚拟主机配置   虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...

随机推荐

  1. Chapter 1. OpenGL基础回顾 - Review of OpenGL Basics

    译自<OpenGL® Shading Language, Second Edition> 本章主要回顾OpenGL应用编程接口,为后续章节中的材质铺垫基础.这并不是详尽的回顾.如果你已经 ...

  2. mongoDb 给表添加+ 删除字段

    1 .添加一个字段.  url 代表表名 , 添加字段 content. 字符串类型. db.url.update({}, {$set: {content:""}}, {multi ...

  3. Ubuntu12.04安装hadoop

    1.      创建hadoop用户组和用户 a.  创建hadoop用户组 sudo addgroup hadoop b.  创建hadoop用户 sudo adduser –ingroup had ...

  4. PHP CodeBase: 判断用户是否手机访问(转)

    随着移动设备的普及,网站也会迎来越来越多移动设备的访问.用适应PC的页面,很多时候对手机用户不友好,那么有些时候,我们需要判断用户是否用手机访问,如果是手机的话,就跳转到指定的手机友好页面.这里就介绍 ...

  5. Linux cpuinfo 详解

     在Linux系统中,如何详细了解CPU的信息呢? 当然是通过cat /proc/cpuinfo来检查了,但是比如几个物理CPU/几核/几线程,这些问题怎么确定呢? 经过查看,我的开发机器是1个物理C ...

  6. [转] 剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)

    http://blog.chinaunix.net/uid-17299695-id-3059078.html PS:Select和Poll都是水平触发,epoll默认也是水平触发 ET模式仅当状态发生 ...

  7. Android常用功能代码块(转)

    1.设置activity无标题,全屏 // 设置为无标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置为全屏模式 getWindow(). ...

  8. Android Studio学习随笔-模拟耗时操作(sleep)

    在这里我申明一点,因为我是挂着VPN去YOUTOBE看的尚学堂的高明鑫老师讲的Android基础学习视频,有些东西他没有讲,而我也没办法,只能等两个星期后学校请老师来的时候进行询问,当然我也会将一些问 ...

  9. Shell 获取当前时间

    #! /bin/bash time=`date '+%Y-%m-%d %H:%M:%S'` # echo $time sql='SELECT `username`, `password` FROM ` ...

  10. Aircrack-ng 工具箱

    官网为:http://www.aircrack-ng.org/, 它就是一个与WiFi 相关的工具啦,可以进行一些注入,抓包.破解WiFI等.里面有很多不同的套件. 另外,http://blog.cs ...