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. eclipse连接远程hadoop集群开发时0700问题解决方案

    eclipse连接远程hadoop集群开发时报错 错误信息: Exception in thread "main" java.io.IOException:Failed to se ...

  2. 实时控制软件第一次作业--CNC软件系统分析

    作者:李君威U201310747 一.该系统有哪些强实时功能需求?需要对哪些实时事件进行实时响应,对允许的实时延迟的数量级进行估计. 答:在数控系统中,位置控制.插补计算.紧急控制等严格实时性任务需要 ...

  3. Solr系列二:Solr与mmseg4j的整合

    mmseg4j是一个很好的中文分词器,solr与mmseg4j的整合也非常简单.如下: 第一步:下载mmseg4j的jar包,网上搜索一下有很多下载地址,如下是csdn上的一个连接:http://do ...

  4. call, apply的用法意义以及区别是什么

    call和apply没有什么大的区别,两者的作用都是:改变对象的this指向的内容. 他们的写法不同,如下: func.call(func1, var1, var2, var3); func.appl ...

  5. 说说CSS学习中的瓶颈

    虽已数年,但未就学习专门写过文章,这回破处了.苍蝇不叮没有缝隙的鸡蛋,领导不做没有跟拍的表演,同样,想到写CSS学习的文章也是有原因的(虽然我的不少行为没有原因). 情景再现(尊重隐私,下面故事中人名 ...

  6. Swift3.0已出坑-适配iOS10,项目迁移Swift3.0问题总结。

    http://www.jianshu.com/p/27fd2a2b32e4 Yes表示swift版本为2.3 NO表示swift版本为3.0

  7. lucene4.0与之前版本的一些改变

    最近在用lucene4.0,因为之前也没用过lucene其它版本,所以也不是很熟悉.但每次上网查资料代码的时候,总发现网友们贴的代码都是之前的版本的.当我拷贝过来的时候总会出问题,去查API的时候,总 ...

  8. Hibernate命名空间怎样实现?

    什么是命名查询?  Hibernate同意在映射文件里定义字符串形式的查询语句.这样的查询方式成为命名查询  使用命名查询有什么优点?  因为使用Hibernate的HQL经常须要在Java代码中写字 ...

  9. Gradle学习目录总结

    如果是你想干的事情,在别人看起来可能是很难的一件事,不过你自己很喜欢,你不会觉得很苦.我开始创业那会是28岁.对我来讲,我创业的目的不是为了自己当老板,我希望有一个平台有一个环境,我可以控制一些资源, ...

  10. __name__属性

    #coding=utf-8#首先我们分别看一下这个模块在不同场景中的__name__的值print __name__ #其次我们看一下__name__属性的常用情况if __name__==" ...