在linux下配置nginx+java+php的环境

来源:互联网 发布:淘宝手机号绑定怎么改 编辑:程序博客网 时间:2024/05/17 03:01

一、配置目标

1、通过lnmp完成基础环境的安装

通过lnmp安装后,相关软件的位置请参考其官方说明。安装后我单独通过气官方说明,升级了nginx的版本

2、配置nginx使之能满足php+java环境在一台机器上的复用


二、相关安装说明

1、将tomcat安装到/usr/local/tomcat6

2、将nginx安装到/usr/local/nginx

3、将java项目安装到tomcat6/webapps下


4、将php相关项目直接安装到/usr/local/下


三、相关配置说明

主要说明几个主配置文件的情况

1、nginx.conf

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. user  www www;  
  2.   
  3. worker_processes 1;  
  4.   
  5. error_log  /home/wwwlogs/nginx_error.log  crit;  
  6.   
  7. pid        /usr/local/nginx/logs/nginx.pid;  
  8.   
  9. #Specifies the value for maximum file descriptors that can be opened by this process.  
  10. worker_rlimit_nofile 51200;  
  11.   
  12. events  
  13.     {  
  14.         use epoll;  
  15.         worker_connections 51200;  
  16.     }  
  17. #fastcgi参数的配置很重要。对性能影响较大  
  18. http  
  19.     {  
  20.         include       mime.types;  
  21.         default_type  application/octet-stream;  
  22.   
  23.         server_names_hash_bucket_size 128;  
  24.         client_header_buffer_size 32k;  
  25.         large_client_header_buffers 4 32k;  
  26.         client_max_body_size 50m;  
  27.   
  28.         sendfile on;  
  29.         tcp_nopush     on;  
  30.   
  31.         keepalive_timeout 60;  
  32.   
  33.         tcp_nodelay on;  
  34.   
  35.         fastcgi_connect_timeout 300;  
  36.         fastcgi_send_timeout 300;  
  37.         fastcgi_read_timeout 300;  
  38.         fastcgi_buffer_size 256k;  
  39.         fastcgi_buffers 8 256k;  
  40.         fastcgi_busy_buffers_size 512k;  
  41.         fastcgi_temp_file_write_size 512k;  
  42.   
  43.         gzip on;  
  44.         gzip_min_length  1k;  
  45.         gzip_buffers     4 16k;  
  46.         gzip_http_version 1.0;  
  47.         gzip_comp_level 2;  
  48.         gzip_types       text/plain application/x-javascript text/css application/xml;  
  49.         gzip_vary on;  
  50.   
  51.         #limit_zone  crawler  $binary_remote_addr  10m;  
  52.   
  53.         #log format  
  54.         log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '  
  55.              '$status $body_bytes_sent "$http_referer" '  
  56.              '"$http_user_agent" $http_x_forwarded_for';  
  57.   
  58. #核心指出了各个域名的配置文件位置,在nginx/conf/vhost目录中  
  59.  include vhost/*.conf;  
  60.   
  61.   
  62.   
  63. }  


2、vhost(在nginx.conf指明了相关域名对应的配置文件位置)

(1)、php项目配置:文件名称shequ.jiuchongju.com.conf

这里我将一个域名的相关配置在这里展示:shequ.jiuchongju.com

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. server  
  2.         {  
  3.                 listen      80;  
  4.                 server_name shequ.jiuchongju.com;  
  5.                 index index.html index.htm index.php;  
  6.                 root  /usr/local/discuzx/upload;  
  7.   
  8.                 location ~ .*\.(php|php5)?$  
  9.                         {  
  10.                                 try_files $uri =404;  
  11.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;  
  12.                                 fastcgi_index index.php;  
  13.                                 include fcgi.conf;  
  14.                         }  
  15.   
  16.                 location /status {  
  17.                         stub_status on;  
  18.                         access_log   off;  
  19.                 }  
  20.   
  21.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  22.                         {  
  23.                                 expires      30d;  
  24.                         }  
  25.   
  26.                 location ~ .*\.(js|css)?$  
  27.                         {  
  28.                                 expires      12h;  
  29.                         }  
  30.   
  31.                 access_log  /home/wwwlogs/access.log  access;  
  32.         }  



(2)、java项目配置:文件名称www.quickbook.cn.conf

这里我指定了一个java项目的配置  www.quickbook.cn

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1.     server {    
  2.         listen       80;    
  3.         server_name  www.quickbook.cn;   
  4.     
  5.         #charset koi8-r;    
  6.     
  7.         access_log  logs/dev/null;    
  8.     
  9.     root   /usr/local/tomcat6/webapps/quickbook/;    
  10.    
  11. #将请求反向代理到tomcat应用服务器上了  
  12.   
  13.  location / {    
  14.                 
  15.              index   index.jsp index.html index.htm ;    
  16.     
  17.              proxy_redirect          off;      
  18.              proxy_set_header        Host            $host;      
  19.              proxy_set_header        X-Real-IP       $remote_addr;      
  20.              proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;      
  21.              client_max_body_size    10m;      
  22.              client_body_buffer_size 128k;      
  23.              proxy_buffers           32 4k;    
  24.              proxy_connect_timeout   3;      
  25.              proxy_send_timeout      30;      
  26.              proxy_read_timeout      30;      
  27.              proxy_pass http://127.0.0.1:8080;    
  28.         }  
  29.   
  30. }  

三、总结

1、主要是nginx将各个子域名的配置放到conf/vhost中独立处理

2、每个vhost下的配置文件都独立生效

3、nginx只是将请求转发到后端的应用服务器上

4、启动的时候需要按照如下次序启动

(1)、启动mysql数据库

(2)、启动tomcat

(3)、启动nginx


From: http://blog.csdn.net/kongqz/article/details/9963555


0 0
原创粉丝点击