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. 开不了的窗_____window.open

    window.open()是原来常用的新开窗口的方式,但是呢,现在会被大多数浏览器阻止掉,默认为是非用户意愿的打开窗口,即广告之类的. 但是通过a链接的事件来open是可以的,因为这样会认为是用户主观 ...

  2. Spring AOP小结

    一. AOP介绍 AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善.OOP ...

  3. struts2的运行原理及配置文件

    struts2官方运行原理图: 1,客户发送请求(url地址就是请求),tomcat接到请求会找到相应的应用web.xml配置文件. 2,web.xml中filter拦截器把你的请求接收到,并进入Fi ...

  4. Getting the first day in a week with T-SQL

    A colleague just asked me if I knew a way to get the first day in a week in SQL Server. While I'm su ...

  5. 冲刺阶段 day 8

    项目进展:教师部分包括教师所属系别.工号.姓名.性别.电话.邮箱.地址.我们已经基本完成窗体的构建和代码编写.可以实现教师信息的增加查询. 代码如下: using System; using Syst ...

  6. Apache axis2 + Eclipse 开发 WebService

    yd小结注意:1.axis2的2个插件的版本必须与引入的jar包匹配,如果不同则可能报以下错误 “没有实现序列化方法”或 “org.apache.axis2.databinding.utils.wri ...

  7. [C++] socket -8 [命名管道]

    ::命名管道不但能实现同一台机器上两个进程通信,还能在网络中不同机器上的两个进程之间的通信机制.与邮槽不同,命名管道是采用基于连接并且可靠的传输方式,所以命名管道传输数据只能一对一进行传输. /* 命 ...

  8. 安全性之DDOS的防护技巧

    网站的信息安全越来越重要,结合自己1年多的互联网金融方面的安全防护做些总结. 后续希望研究并运用: 1.加密算法 2.DDOS的防护技巧 3.跨站点请求伪造 4.XSS攻击 5.文件上传漏洞 6.信息 ...

  9. [Java拾遗三]JavaWeb基础之Servlet

    Servlet    1,servlet介绍        servlet是一项动态web资源开发技术.        运行在服务器端.        作用:处理业务逻辑,生成动态的内容,返回给浏览器 ...

  10. Android Studio 生成Release版,报Warning的解决办法

    转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6242227.html 请尊重知识产权!!! 同步更新到CSDN:http://blog.csdn.net/ ...