Nginx与PHP部分

mkdir /www/php -p
echo -e "<?php\n\tphpinfo();\n?>" > /www/php/index.php
vim /usr/local/nginx/conf/nginx.conf
#==============Nginx代理PHP端===================
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#上面那个注视掉,改成下面的不然就出FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream这个错
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
}

Nginx+Tomcat部分

mkdir /www/jsp -p
echo "this is jsp" >>/www/jsp/index.jsp
echo "this is jsp" >>/www/do/index.do
vim /usr/local/tomcat/conf/server.xml

配置Tomcat中的server.conf,修改tomcat家目录

vim /usr/local/tomcat/conf/server.xml
<!-- 索搜此项修改默认WEB端口,这里默认保持不变 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- 可以修改域名或者IP,但作代理请保持localhost -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 新增此项修改WEB的家目录 -->
<Context path="" docBase="/www"></Context>

配置nginx中的nginx.conf,让其能代理jsp网页

#==========Nginx代理JSP段================
location ~ (\.jsp)|(\.do)$ {
index index.jsp;
proxy_pass http://127.0.0.1:8080; #来自jsp请求交给tomcat处理
proxy_redirect off;
proxy_set_header Host $host; #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
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 ; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout ; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
location ~ .*\.(gif|jpg|png|bmp|swf)$ #由nginx处理静态页面
{
expires 30d; #使用expires缓存模块,缓存到客户端30天
}
error_page /.html; #错误页面
error_page /50x.html;
location = /50x.html {
root html;
}

------------------------------------------

完整的nginx.conf文件,仅供参考

user  www;
worker_processes ;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections ;
} http {
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 main;
server_names_hash_bucket_size ;
client_header_buffer_size 32k; #客户端请求头部的缓冲区大小,一般一个请求头的大小不会超过1k
large_client_header_buffers 32k; #客户请求头缓冲大小 nginx默认会用client_header_buffer_size这个buffer来读取header值
client_max_body_size 8m; #设定通过nginx上传文件的大小
sendfile on;
keepalive_timeout ; #===================重要位置============
fastcgi_connect_timeout ; #指定连接到后端FastCGI的超时时间。
fastcgi_send_timeout ; #向FastCGI传送请求的超时时间,这个值是指已经完成两次握手后向FastCGI传送>请求的超时时间。
fastcgi_read_timeout ; #接收FastCGI应答的超时时间,这个值是指已经完成两次握手后接收FastCGI应答>的超时时间。
fastcgi_buffer_size 254k; #指定读取FastCGI应答第一部分需要用多大的缓冲区
fastcgi_buffers 256k; #指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答。
fastcgi_busy_buffers_size 512k; #这个指令我也不知道是做什么用,只知道默认值是fastcgi_buffers的两倍

fastcgi_temp_file_write_size 512k; #在写入fastcgi_temp_path时将用多大的数据块,默认值是fastcgi_buffers的两倍。
#gzip on;
gzip on; #该指令用于开启或关闭gzip模块(on/off)
gzip_min_length 1k; #设置允许压缩的页面最小字节数,页面字节数从header头得content-length中进行获>取
gzip_buffers 16k; #设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流
gzip_http_version 1.0; #识别http的协议版本
gzip_comp_level ; #gzip压缩比,1压缩比最小处理速度最快
#匹配mime类型进行压缩,无论是否指定,”text/html”类型总是会被压缩的
gzip_types text/plain application/x-javascript text/css application/xml text/javascript;
gzip_vary on; #和http头有关系,加个vary头,给代理服务器用的
server {
listen ;
server_name 自己的网站名;
#charset koi8-r;
#access_log logs/host.access.log main;
root /www;
location / {
index index.html index.htm index.jsp index.php;
}
#===========PHP段=================
location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#============Tomcat段=============
location ~ (\.jsp)|(\.do)$ {
index index.jsp;
proxy_pass http://127.0.0.1:8080; #来自jsp请求交给tomcat处理
proxy_redirect off;
proxy_set_header Host $host; #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
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 ; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout ; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
location ~ .*\.(gif|jpg|png|bmp|swf)$ #由nginx处理静态页面
{
expires 30d; #使用expires缓存模块,缓存到客户端30天
}
error_page /.html; #错误页面
error_page /50x.html;
location = /50x.html {
root html;
} }

ok,就到这里了

参考:Linux下Nginx+Tomcat整合的安装与配置

最新文章

  1. RMAN备份失败: ORA-19502 &amp; ORA-27072: File I/O error
  2. 【转】Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式
  3. 20个基于 WordPress 搭建的精美网站
  4. 在VMware上安装CentOS-6.5 minimal - 安装VMware Tools
  5. September 11th 2016 Week 38th Sunday
  6. 检测php网站是否已经被攻破的方法
  7. std::string和int类型的相互转换(C/C++)
  8. 广州Uber优步司机奖励政策(2月1日~2月7日)
  9. XML读写文件辅助类
  10. 清华申请退学博士作品:完全用Linux工作,凸Windows
  11. java thread reuse(good)
  12. 读书笔记之ado.net entity framework
  13. C语言程序设计第六次作业——循环结构(2)
  14. JSOUP如何POST只含JSON格式的数据
  15. MFC VC++获取当前程序的运行路径
  16. 【POJ1958】汉诺塔+
  17. linq与lambda 常用查询语句写法对比
  18. java浅复制与深使用接口实现
  19. MySQL中int(5) 中的5代表什么意思?
  20. 在laravel之外使用eloquent

热门文章

  1. H5调用本地摄像头
  2. As3.0 类的【枚举】
  3. iptables防火墙详解
  4. 微信支付WxpayAPI_php_v3(一)sdk简介与错误修改
  5. pci 相关资料
  6. hh monitor
  7. ionic中 .col : 默认的定宽列
  8. C#抓取页面时候,获取页面跳转后的地址
  9. C语言根据函数名调用对应的函数
  10. oracle_一次移动数据库dbf文件的操作