Nginx 设置域名转向配置

简介:
#运行用户
#user www-data;
  
#启动进程,通常设置成和cpu的数量相等
worker_processes 2;

#全局错误日志及PID文件
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;

#工作模式及连接数上限
events {
    #单个后台worker process进程的最大并发链接数
    worker_connections 1024; 
}

#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
    #设定mime类型,类型由mime.type文件定义
    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;
    
    #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile        on;
    #tcp_nopush     on;
    
    #连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #开启gzip压缩
    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    #设定请求缓冲
    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;
    
    ############################################################
    # tomcat 
    # listen    :   localhost:80
    # redirect  :   localhost:81
    ############################################################
    server{
        listen 80;                                      #侦听端口
        server_name  115.55.31.102;                   #定义使用www.xx.com访问
        
        #charset koi8-r;
        
        access_log  logs/localhost81.access.log;    #设定本虚拟主机的访问日志

        #默认请求
        location / {
            root /;                                     # 定义服务器的默认网站根目录位置
            index index.aspx;                           # 定义首页索引文件的名称
            proxy_pass  http://localhost:81 ;     #请求转向mysvr 定义的服务器列表  
        }
 

        #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   /root;
        } 
    }
    

    
    ############################################################
    # Tomcat 
    # listen    :   ts2121.bdqnbky.com:80
    # redirect  :   ts2121.bdqnbky.com:8080
    ############################################################
    server {
        listen 80;                                      #侦听端口
        server_name  115.55.31.102;                   #定义使用www.xx.com访问
        
        #charset koi8-r;
        
        access_log  logs/localhost8080.com.access.log;    #设定本虚拟主机的访问日志

        #默认请求
        location / {
            root /;                                     # 定义服务器的默认网站根目录位置
            index  index.html;                           # 定义首页索引文件的名称
            proxy_pass  http://localhost:8080;   #请求转向mysvr 定义的服务器列表  
        }

        #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   /root;
        }

        # 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           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    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;
        #}
    }

    ############################################################
    # Tomcat 
    # listen    :   ts2122.bdqnbky.com:80
    # redirect  :   ts2122.bdqnbky.com:8080
    ############################################################
    server{
        listen 80;                                      #侦听端口
        server_name  hh.xx.com;                #定义使用www.xx.com访问
        
        #charset koi8-r;
        
        access_log  logs/hh.xx.com.access.log; #设定本虚拟主机的访问日志

        #默认请求
        location / {
            root /;                                     # 定义服务器的默认网站根目录位置
            #index index.jsp;                          # 定义首页索引文件的名称
            proxy_pass  http://hh.xx.com:8081; #请求转向mysvr 定义的服务器列表  
        }

        #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   /root;
        } 
    }
    
本文转自 netcorner 博客园博客,原文链接:  http://www.cnblogs.com/netcorner/p/7426385.html ,如需转载请自行联系原作者

}



相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
相关文章
|
1月前
|
应用服务中间件 nginx
Nginx中如何配置中文域名?
Nginx中如何配置中文域名?
40 0
|
3月前
设置博客域名跳转实现方案(免费版)
设置博客域名跳转实现方案(免费版)
42 1
|
3天前
|
域名解析 缓存 负载均衡
Nginx正向代理域名的配置
Nginx正向代理域名的配置
|
1月前
|
负载均衡 应用服务中间件 nginx
|
1月前
|
Unix 应用服务中间件 Linux
nginx的CPU亲和性设置和优先级设置
nginx的CPU亲和性设置和优先级设置
|
2月前
|
应用服务中间件 nginx
nginx 根据域名转发
nginx 根据域名转发
42 0
|
3月前
|
域名解析 网络协议 网络安全
在阿里云DNS上已经完成了域名解析的设置,但是仍然不能使用邮箱
在阿里云DNS上已经完成了域名解析的设置,但是仍然不能使用邮箱【1月更文挑战第17天】【1月更文挑战第81篇】
48 1
|
4月前
|
应用服务中间件 Linux 网络安全
源码方式安装nginx及其依赖并设置服务开机启动
源码方式安装nginx及其依赖并设置服务开机启动
115 0
|
应用服务中间件 PHP nginx
nginx 和php设置上传大小及可以提交的内容限制
1. 以下代码加入 /etc/nginx/nginx.conf 文件中的 http{ ... } 块中 client_max_body_size 8M; 2. PHP 设置上传大小 打开 /etc/php5/fpm/php.
1012 0
|
22天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
24 0