nginx多站点配置

摘要:
$1last;break;}location~.php${root/data/wwwxx;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}#denyaccessto.htaccessfiles,ifApache'sdocumentroot#concurswithnginx'sone##location~/.ht{#denyall;#}}https-ssl带证书配置站点web.confserver{listen443;server_namewww.xx.cn;if{rewrite^/(.*)$https://www.xx.cn/$1permanent;}sslon;ssl_certificate/data/ssl/xx.cn.crt;ssl_certificate_key/data/ssl/xx.cn.key;#charsetkoi8-r;access_log/data/logs/wwwxx.access.logmain;root/data/wweb;indexindex.htmlindex.htmindex.php;error_page404/404.html;location=/404.html{root/usr/share/nginx/html;}#redirectservererrorpagestothestaticpage/50x.html#error_page500502503504/50x.html;location=/50x.html{root/usr/share/nginx/html;}#proxythePHPscriptstoApachelisteningon127.0.0.1:80##location~.php${#proxy_passhttp://127.0.0.1;#}#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000#location/{if(!

主配置文件 nginx.conf:

user www;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections  102400;
}
http {
    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  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

站点1配置文件:one.conf

server {
    listen       80;
    server_name  www.xx.cn;
    #charset koi8-r;
    access_log  /data/logs/wwwxx.access.log  main;

    location / {
        root   /data/wwwxx;
        index  index.html index.htm index.php;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # 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
    #
    if (!-e $request_filename) {
        #rewrite ^/(.*) /index.php?$1 last;
    rewrite ^(?!/favicon)(?!/data)(?!/static)(?!/MP)(.*)$ /index.php?$1 last;
        break;
    }
    location ~ .php$ {
        root           /data/wwwxx;
        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;
    #}
}

https-ssl带证书配置站点 web.conf

server {
    listen       443;
    server_name  www.xx.cn ;
    if ($host = 'xx.cn'){
        rewrite ^/(.*)$ https://www.xx.cn/$1 permanent;
}
    ssl on;
    ssl_certificate /data/ssl/xx.cn.crt;
    ssl_certificate_key /data/ssl/xx.cn.key;
    #charset koi8-r;
    access_log  /data/logs/wwwxx.access.log  main;
        root   /data/wweb;
        index  index.html index.htm index.php;
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # 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 /{
    if (!-e $request_filename) {
        #rewrite ^/(.*) /index.php?$1 last;
      rewrite ^(?!/pc)(?!/static)(?!/robots)(.*)$ /index.php?$1 last;
        break;
    }
  }
    location ~.php$ {
        root           /data/wweb;
        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;
    #}
}

反向代理站点配置 two.conf

upstream two_web{
    server 127.0.0.1:8088 weight=1;
    server 127.0.0.1:8081 weight=2;
}
server {
    listen       80;
    server_name  www.xx.com;
    #charset koi8-r;
    access_log  /data/logs/xx.access.log  main;
    # Load configuration files forthe default server block.
    include /etc/nginx/default.d/*.conf;
    location / {
        index  index.htm index.html;
        proxy_pass   http://two_web;    #在这里设置一个代理,和upstream的名字一样
        #以下是一些反向代理的配置可删除
        proxy_redirect             off; 
        #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
        proxy_set_header           Host $host; 
        proxy_set_header           X-Real-IP $remote_addr; 
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for; 
        client_max_body_size       10m; #允许客户端请求的最大单文件字节数
        client_body_buffer_size    128k; #缓冲区代理缓冲用户端请求的最大字节数
        proxy_connect_timeout      300; #nginx跟后端服务器连接超时时间(代理连接超时)
        proxy_send_timeout         300; #后端服务器数据回传时间(代理发送超时)
        proxy_read_timeout         300; #连接成功后,后端服务器响应时间(代理接收超时)
        proxy_buffer_size          4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
        proxy_buffers              4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
        proxy_busy_buffers_size    64k; #高负荷下缓冲大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

静态资源访问配置 image.conf

server {
    listen       80;
    server_name  img002.xx.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location /{
        root   /data/www/resource/;
        index  index.html index.htm;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

免责声明:文章转载自《nginx多站点配置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇字体文件放入CDN服务器中,跨域问题(IIS版)SSL协议具体解释下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

nginx重启

转载自:https://www.cnblogs.com/codingcloud/p/5095066.html 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/ngin...

Apache和nginx相关知识

1 Apache和nginx相关知识 1.1 Apache配置文件 Listen 80 Listen主要侦听web服务端口状态,默认为:80,即侦听所有的地址的80端口,注意这里也可以写成IP地址的侦听形式,不写即默认的地址:0.0.0.0 ServerName 127.0.0.1:80/localhost:80 此选项主要用指定Apache默认的服务器名...

vue 跨域请求,后端cookie session取不到

虽然后端设置了可以跨域请求,但是后台设置到cookie中的session取不到!这时候mac电脑自己设置nginx代理! mac电脑系统重装了,记录一下安装nginx的过程: 1、打开终端(cmd) 2、安装Command Line tools xcode-select --install 3、安装brew命令 1 ruby -e "$(curl ...

Ansible-基础

Ansible架构 Inventory 主机清单,可以对主机分组 ansible-hoc ansible的命令,适用临时场景 ansible-playbook ansible是一个场景的集合,是YAML语言 被控端: 被管理的主机 连接协议:ansible是用的ssh协议,所以被控端不需要安装额外的agent,这也是 ansible-galaxy 连...

Nginx 笔记与总结(13)Nginx 的 gzip 压缩

使用 FireFox(40.0)访问博客园(http://www.cnblogs.com/),观察 http 头信息 请求头信息: Accept-Encoding gzip, deflate 表示浏览器接受的压缩方式有 gzip 和 deflate 响应头信息: Content-Encoding gzip 表示服务器返回内容的压缩方式是 gzip 注意...

第一课:docker基本知识

1.什么是docker 使用最广泛的开源容器引擎 一种操作系统级的虚拟化技术 依赖于linux内核特性:namespace和cgroups 一种简单的应用程序打包工具 2.docker的设计目标 提供简单的应用程序打包工具 开发人员和运维人员职责逻辑分离 多环境保持一致性 3.docker的基本组成 docker client 客户端 docker d...