nginx的使用配置
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的使用配置的更多相关文章
- nginx + SSL优化配置
nginx + SSL优化配置: #http段添加如下配置项: http { ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户 ...
- nginx安装与配置
一.在线安装 ubuntu 安装 sudo apt-get install nginx 安装后文件结构为: 配置文件:/etc/nginx ,并且每台虚拟主机已经安排在 /etc/nginx/site ...
- windows下nginx安装、配置与使用(转载)
目前国内各大门户网站已经部署了Nginx,如新浪.网易.腾讯等:国内几个重要的视频分享网站也部署了Nginx,如六房间.酷6等.新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx ...
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...
- nginx入门篇----nginx服务器基础配置
1.nginx.conf文件结构... #全局块 events{ ... } http #http块{ ...
- 高流量站点NGINX与PHP-fpm配置优化(译)
使用Nginx搭配PHP已有7年的这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置. 以下正是这方面的一些提示和建议: 1. 将TCP切换为UNIX域套接字 UNIX域套接字相比T ...
- nginx反向代理配置及优化
nginx反向代理配置及优化前言: 由于服务器apache抗不住目前的并发.加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反 ...
- LVS + Keepalived + Nginx安装及配置
1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...
- windows下nginx+php简单配置
Nginx+php运行环境搭建 虽然目前nginx使用很广泛,在大陆主流的互联网站点或多或少会用到这个俄国人开发的小应用(占用资源小).但是我这个土鳖还是第一次自己独立配置,网上资料不少,但是还是遇到 ...
- nginx虚拟主机配置
nginx虚拟主机配置 虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...
随机推荐
- JSP执行过程详解
复习JSP的概念 JSP是Java Server Page的缩写,在传统的HTML页面中加入JSP标签和java的程序片段就构成了JSP. JSP的基本语法:两种注释类型.三个脚本元素.三个元素指令. ...
- [Angular 2] Custom Validtors
Create a custom validtor which only accepts the string start with '123'; function skuValidator(contr ...
- android bitmap的 一些简单操作
/** 获取 drawable 的图片 可以循环 1.图名 2.drawable 3.包名 **/ int imgid = getResources().getIdentifier("ic_ ...
- Swift的闭包(二):捕获值
闭包可以从定义它的上下文中捕获常量和变量. 在Swift中,捕获值最简单的例子是嵌套函数,举个例子: func makeIncrementer(forIncrement amount: Int) -& ...
- Delpoyment assembly
遇见异常: java.lang.ClassNotFoundException: 原因:没有对tomcat进行依赖说明 解决: properties - Delpoyment assembly 将tom ...
- vim 学习相关记录
VIM 相关内容****************** vim 的三个模式: 编辑模式 --> 输入模式 --> 末行模式 编辑模式: 通常键入键盘值被理解成一个操作; 如: dd(删除行) ...
- 【iOS UISearchBar父控件是UIScrollView时,上移的问题】
如果UISearchViewController的父控件是UIScrollView,点击UISearchBar后,它会移出控制器外.如下,使用UIScrollView作为"消息"和 ...
- Android深入浅出之 AudioTrack分析
Android深入浅出之Audio 第一部分 AudioTrack分析 一 目的 本文的目的是通过从Audio系统来分析Android的代码,包括Android自定义的那套机制和一些常见类的使用,比如 ...
- uva 1391 Astronauts(2-SAT)
/*翻译好题意 n个变量 不超过m*2句话*/ #include<iostream> #include<cstdio> #include<cstring> #inc ...
- 三星I9308(移动版)正确Root的方法,进入正确的recovery的关键(网上很多方法是误导)
三星I9308(移动版)正确Root的方法,进入正确的recovery的关键(网上很多方法是误导) 1)首先在电脑上安装手机驱动:下载地址:点击这里下载 2)手机设置USB调试 方法1:设置- ...