2013-12-22 12:52:01
来 源
IT技术网
Apache
本文介绍Linux系统配置Nginx+Java+PHP服务器环境,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。

一、配置目标

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

user  www www;

worker_processes 1;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

}

#fastcgi参数的配置很重要。对性能影响较大

http

{

include       mime.types;

default_type  application/octet-stream;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;

sendfile on;

tcp_nopush     on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 256k;

fastcgi_buffers 8 256k;

fastcgi_busy_buffers_size 512k;

fastcgi_temp_file_write_size 512k;

gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#limit_zone  crawler  $binary_remote_addr  10m;

#log format

log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

#核心指出了各个域名的配置文件位置,在nginx/conf/vhost目录中

 include vhost/*.conf;

}

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

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

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

server

{

listen      80;

server_name www.server110.com;

index index.html index.htm index.php;

root  /usr/local/discuzx/upload;

location ~ .*.(php|php5)?$

{

try_files $uri =404;

fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fcgi.conf;

}

location /status {

stub_status on;

access_log   off;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}

location ~ .*.(js|css)?$

{

expires      12h;

}

access_log  /home/wwwlogs/access.log  access;

}

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

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

    server {

listen       80;

server_name  www.server110.cn;

#charset koi8-r;

access_log  logs/dev/null;

root   /usr/local/tomcat6/webapps/quickbook/;

#将请求反向代理到tomcat应用服务器上了

 location / {

index   index.jsp index.html index.htm ;

proxy_redirect          off;

proxy_set_header        Host            $host;

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_buffers           32 4k;

proxy_connect_timeout   3;

proxy_send_timeout      30;

proxy_read_timeout      30;

proxy_pass http://127.0.0.1:8080;

}

}

三、总结

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

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

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

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

(1)、启动mysql数据库

(2)、启动tomcat

(3)、启动nginx

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。