一、配置目标
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/下
三、相关配置说明
几个主要的nginx配置文件
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_nopushon;
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_buffers4 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 shequ.jiuchongju.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.plcxue.com.conf
这里指定一个java项目的配置 www.plcxue.com
复制代码 代码示例:
server {
listen 80;
server_name www.plcxue.com;
#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_headerHost $host;
proxy_set_headerX-Real-IP $remote_addr;
proxy_set_headerX-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/ target=_blank class=infotextkey>mysql数据库
2)、启动tomcat
3)、启动nginx