nginx 反向代理 与 Apache backend的配置联合配置:
说明: nginx 将http映射到Apache上的特定子目录。
配置方法步骤:
1.  设置域名, 子域名映射到指定服务器ip,
2. nginx设置好server ,以及对应的目录, 或者 转发到指定Apache端口。
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
 
        root /usr/share/nginx/html;
        index index.html index.htm;
 
        # Make site accessible from http://localhost/
        server_name localhost;
 
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
 
        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}
#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/share/nginx/html;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
        #       fastcgi_index index.php;
 #       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   nginx.xxxx.com;
        location / {
                root    /usr/share/nginx/html/www.xxxx.com;
                index   index.html;
        }
}

server{
        listen    80;
        server_name     www.xxxx.com apache.xxxx.com;

        index   index.html;
        location / {
                proxy_pass http://localhost:8080/www.xxxx.com/;
                proxy_redirect default;
        }
}
 
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#       listen 8000;
#       listen somename:8080;
#       server_name somename alias another.alias;
#       root html;
#       index index.html index.htm;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}
 
3. Apache 设置好ports.conf , 设置为2中相同(8080), 另外注意配置 sites_enable文件夹下的文件中的端口。
 
<VirtualHost *:8080>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName www.xxxx.com
 
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
 
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
 
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
 
4. 启动nginx 加载新配置, 重启Apache
 4.1  启动nginx,只需nginx即可,若是修改配置后重新启动,则需要nginx -s reload.  关闭: nginx -s stop
 4.2  apache2ctl restart
 
5. 查看端口占用情况: netstat -anop | grep 80
 
6. Apache 的 mod_expires 与 mod_cache
Apache的过期策略可以通过apache的mod_expires和mod_headers两个模块设置:
 
1)模块mod_expires设置:
允许通过配置文件控制HTTP的"Expires"和"Cache-Control"头内容
mod_expires 模块的主要作用是自动生成页面头部信息中的 Expires 标签和 Cache-Control 标签,从而降低客户端的访问频率和次数,达到减少不必要流量和增加访问速度的目的
mod_expires 是 apache 众多模块中配置比较简单的一个,它一共只有三条指令
ExpiresActive 指令:打开或关闭产生”Expires:”和”Cache-Control:”头的功能。
ExpiresByType 指令:指定MIME类型的文档(例如:text/html)的过期时间。
ExpiresDefault 指令:默认所有文档的过期时间。
 
过期时间的写法
“access plus 1 month”
“access plus 4 weeks”
“now plus 30 days”
“modification plus 5 hours 3 minutes”
A2592000
M604800
access、now及A 三种写法的意义相同,指过期时间从访问时开始计算。
modification及M 的意义相同,指过期时间是以被访问文件的最后修改时间开始计算。
所以,后一种写法只对静态文件起作用,而由脚本生成的动态页面不受它的作用
 
配置实例:
 
    ExpiresActive On(开启mod_expires功能)
    ExpiresDefault "access plus 6 months"(默认的过期时间是6个月)
    ExpiresByType image/* "access plus 10 years"(图片的文件类型缓存时间为10年)
    ExpiresByType text/* "access plus 10 years"(文本类型缓存时间为10年)
    ExpiresByType application/* "access plus 30 minutes"(application文件类型缓存30分钟)
 
验证:image/jpeg 缓存时间为315360000s(10年)
 
 
如果将image/jpeg设置为不缓存(将max-age设置为0s):
 
#   ExpiresByType image/* "access plus 10 years"
ExpiresByType image/*  A0
 
2)模块mod_headers设置:
 
   # YEAR(flv,gif,ico文件类型的缓存时间为1年)
 
Header set Cache-Control “max-age=2592000″
 
 
# WEEK(pdf.swf,js,css缓存时间为一周)
 
Header set Cache-Control “max-age=604800″
 
 
# NEVER CACHE(jsp.swf,ico文件类型不缓存)
 
Header set Expires “Thu, 01 Dec 2003 16:00:00 GMT”
Header set Cache-Control “no-store, no-cache, must-revalidate”
Header set Pragma “no-cache”

nginx 反向代理 与 Apache backend的配置联合配置的更多相关文章

  1. nginx反向代理转发apache配置 之 cookie去哪儿了?

    在公司接手了个微信项目,由于微信环境下访问网站需要使用对外开放的域名,所以有相关问题,都是直接运维同事帮忙处理. 原理是这样: 方案一: 1. 将域名解析指向测试服务器的地址: 2. 开放相关端口访问 ...

  2. Linux下nginx反向代理负载均衡几种方式以及配置

    下面以ip地址192.168.1.1 和192.168.1.2举例 1.轮询   (1).轮询:每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除.  upstream ...

  3. 使用nginx反向代理,一个80端口下,配置多个微信项目

    我们要接入微信公众号平台开发,需要填写服务器配置,然后依据接口文档才能实现业务逻辑.但是微信公众号接口只支持80接口(80端口).我们因业务需求需要在一个公众号域名下面,发布两个需要微信授权的项目,怎 ...

  4. nginx反向代理结合apache和php的配置示例

    .前端nginx主配置文件 # cat nginx.conf worker_processes ; #pid logs/nginx.pid; pid /data/www/logs/nginx.pid; ...

  5. 使用SSL配置Nginx反向代理的简单指南

    反向代理是一个服务器,它接收通过Web发出的请求,即http和https,然后将它们发送到后端服务器(或服务器).后端服务器可以是单个或一组应用服务器,如Tomcat,wildfly或Jenkins等 ...

  6. Nginx反向代理配置可跨域

    由于业务需要,同一项目中的前端代码放在静态环境中,而后端代码放在tomcat中,但此时问题却出现了:前端使用ajax请求后端获取数据时出现如下报错 XMLHttpRequest cannot load ...

  7. nginx反向代理-解决前端跨域问题

    1.定义 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制了跨域访问,也就是不允许跨域请求资源.注意:跨域限制访 ...

  8. VUE线上通过nginx反向代理实现跨域

    1.NGINX反向代理实现跨域 VUE代码中配置参考上一篇文章 nginx配置,红色框线内: 代码: location /list { proxy_set_header X-Real-IP $remo ...

  9. 配置LANMP环境(7)-- 配置nginx反向代理,与配置apache虚拟主机

    一.配置nginx反向代理 1.修改配置文件 vim /etc/nginx/nginx.conf 在35行http下添加一下内容: include /data/nginx/vhosts/*.conf; ...

随机推荐

  1. linux中实现自动交互的3中方法

    本文参考了 http://os.51cto.com/art/200912/167898.htm 有些命令例如ftp需要交互,有三种方法可以实现. 方法一(重定向)简单直观,也经常有实际应用,但是在自动 ...

  2. 模板短信接口调用java,pythoy版(一) 网易云信

    说明 短信服务平台有很多,我只是个人需求,首次使用,算是测试用的,故选个网易(大公司). 稳定性:我只测试了15条短信... 不过前3条短信5分钟左右的延时,后面就比较快.... 我只是需要发短信,等 ...

  3. Windows 8.1 应用再出发 - 几种新增控件(1)

    Windows 8.1 新增的一些控件,分别是:AppBar.CommandBar.DatePicker.TimePicker.Flyout.MenuFlyout.SettingsFlyout.Hub ...

  4. HTML回顾

    <frameset>和<body>是同一级的,已经在html5中被弃用    结合---->    效果   注意::::span标签不自动换行****

  5. requireJS 用法

    requireJS使用教程 2.0 常用方法 requirejs.config : 为模块指定别名 requirejs : 将写好的模块进行引入,根据模块编写主代码 define : 编写模块 htm ...

  6. 【原创】-- Linux 下利用dnw进行USB下载

    原帖地址: http://blog.csdn.net/jjzhoujun2010 http://blog.csdn.net/yf210yf/article/details/6700391 http:/ ...

  7. PROTEL DXP原理图编译 常见错误与处理方法

    一, [Warning] AUDIO.SCH Extra Pin R509-1 in Normal of part R509      [Warning] AUDIO.SCH Extra Pin R5 ...

  8. Orchard Platform v1.8 发布

    发布说明: 1. 添加Json格式数据文件支持.2. 彻底删除了Settings, Modules, Themes模块.3. 删除了默认的ContentType,Site和User.4. 支持空库(无 ...

  9. 通过LinQ查询字符出现次数

    在一个项目中使用到一个问卷调查,在用户完成之后,需要统计所有题目中哪一个选项被选中次数最多. 我的实现方法是将所有题目选中的选项拼接为一个字符串,如:ABCADAA 在分析被选中次数的时候最初是将字符 ...

  10. 个性二维码开源专题<前背景>

    //设置图片资源 private Image imgAgo; public override void SetParam() { base.SetParam(); // 读取前背景 string _i ...