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配置 之 cookie去哪儿了?
在公司接手了个微信项目,由于微信环境下访问网站需要使用对外开放的域名,所以有相关问题,都是直接运维同事帮忙处理. 原理是这样: 方案一: 1. 将域名解析指向测试服务器的地址: 2. 开放相关端口访问 ...
- Linux下nginx反向代理负载均衡几种方式以及配置
下面以ip地址192.168.1.1 和192.168.1.2举例 1.轮询 (1).轮询:每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. upstream ...
- 使用nginx反向代理,一个80端口下,配置多个微信项目
我们要接入微信公众号平台开发,需要填写服务器配置,然后依据接口文档才能实现业务逻辑.但是微信公众号接口只支持80接口(80端口).我们因业务需求需要在一个公众号域名下面,发布两个需要微信授权的项目,怎 ...
- nginx反向代理结合apache和php的配置示例
.前端nginx主配置文件 # cat nginx.conf worker_processes ; #pid logs/nginx.pid; pid /data/www/logs/nginx.pid; ...
- 使用SSL配置Nginx反向代理的简单指南
反向代理是一个服务器,它接收通过Web发出的请求,即http和https,然后将它们发送到后端服务器(或服务器).后端服务器可以是单个或一组应用服务器,如Tomcat,wildfly或Jenkins等 ...
- Nginx反向代理配置可跨域
由于业务需要,同一项目中的前端代码放在静态环境中,而后端代码放在tomcat中,但此时问题却出现了:前端使用ajax请求后端获取数据时出现如下报错 XMLHttpRequest cannot load ...
- nginx反向代理-解决前端跨域问题
1.定义 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制了跨域访问,也就是不允许跨域请求资源.注意:跨域限制访 ...
- VUE线上通过nginx反向代理实现跨域
1.NGINX反向代理实现跨域 VUE代码中配置参考上一篇文章 nginx配置,红色框线内: 代码: location /list { proxy_set_header X-Real-IP $remo ...
- 配置LANMP环境(7)-- 配置nginx反向代理,与配置apache虚拟主机
一.配置nginx反向代理 1.修改配置文件 vim /etc/nginx/nginx.conf 在35行http下添加一下内容: include /data/nginx/vhosts/*.conf; ...
随机推荐
- 表单验证代码实例:jquery.validate.js表单验证插件
jquery.validate.js是JQuery旗下的一个验证插件,借助JQuery的优势,我们可以迅速验证一些常见的输入,并且可以自己扩充自己的验证方法.使用前请先下载必要的JQuery插件:jq ...
- OkHttp使用进阶 译自OkHttp Github官方教程
版权声明: 欢迎转载,但请保留文章原始出处 作者:GavinCT 出处:http://www.cnblogs.com/ct2011/p/3997368.html 没有使用过OkHttp的,可以先看Ok ...
- JS代码风格指南
一.基本格式 缩进 建议每级4个空格,可以给编辑器设置tab = 4个空格,自动转换 分号 不要省略分号,防止ASI(自动插入分号)错误 行宽 每行代码不超过80个字符,过长应该用操作符手动断行 断行 ...
- [译]面向初学者的Asp.Net状态管理技术
介绍 本文主要讲解Asp.Net应用程序中的状态管理技术(Asp.Net中有多种状态管理技术),并批判性地分析所有状态管理技术的优缺点. 背景 HTTP是无状态的协议.客户端发起一个请求,服务器响应完 ...
- [转]Sublime Text 2 设置文件详解
Sublime Text 2是那种让人会一眼就爱上的编辑器,不仅GUI让人眼前一亮,功能更是没的说,拓展性目前来说也完全够用了,网上介绍软件的文章和推荐插件的文章也不少,而且很不错,大家可以去找找自己 ...
- [C++] 将 mp3 等音乐资源以资源形式嵌入 exe 文件中
引用:http://www.easyx.cn/skills/View.aspx?id=6 本文讲解怎样将 mp3 等音乐资源以资源形式嵌入 exe 文件中,并通过 mciSendString 调用.嵌 ...
- [JS13] ActivetX
<HTML> <head> <title>JavaScript Unleashed</title> <script type="text ...
- thrift之TTransport层的分帧传输类TFramedTransport
帧传输类就是按照一帧的固定大小来传输数据,所有的写操作首先都是在内存中完成的直到调用了flush操作,然后传输节点在flush操作之后将所有数据根据数据的有效载荷写入数据的长度的二进制块发送出去,允许 ...
- ios 学习常用网站
一 ,别的blog上的内容 iPhone 4 与iPad开发基础教程 一.邮件列表: 1.cocoa-dev http://lists.apple.com/mailman/listinfo/cocoa ...
- CSS扇形展开效果
知识点预备: [1]CSS3中特别重要的transform中的rotate(),现在transform可以将元素进行2D和3D变形. 2D transform常用的transform-function ...