moodle服务器优化,linux服务器优化同理apache nginx tomcat php php-fpm loadruner ab nginx 虚拟目录
一台服务器,主要有两个应用,一个是moodle,一个是tomcat 8080端口。
moodle在 html/www文件夹下,tomcat应用在tomcat安装目录下,分别访问均正常。其中由一个www目录下index.html文件作为链接跳转。
起初是安装在Apache下,并且用ajp做跳转到tomcat服务
xxx.com/moodle/
index--xxx.com:8080/app
xxx.com/app
第二和第三个是同样的,只是第三因为有时单位出口,8080被封,备用的出口
现在转到nginx上,第一个几乎不用做修改就可以,只是主要php文件的解析
第二个不用管,因为本来tomcat的应用就是由单独服务器处理的,其中静态html网页也交给tomcat处理
第三个花了很久完成
1)本来想写单独conf文件,但是servername只有一个,要么第三个能用要么第二个能用
2)想用负载均衡来做,因为需要加虚拟目录,实现起来磕磕绊绊,放弃了
3)location 区块处理,成功了,但是在一个隐含提交按钮上,总是指向127.0.0.1:8080,所以修改了director开关
总之这次的处理,长了不少见识,一个域名下做了这么多的不同应用
优化等以后再进行吧
nginx conf
# For more informaition on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
#include /etc/nginx/conf.d/moodle.conf
user nginx;
master_process on;
worker_processes 8;
#cpu number
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
#Linux 2.6
use epoll;
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 50m;
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;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
upstream tomcatoj {
server 127.0.0.1:8009 ;
#jvm_route $cookie_JSESSIONID reverse;
}
}
server {
listen 80 default_server; #当输入ip时,会访问aaa.com
server_name oi.sipxhsy.cn ; #这个应该是最好的写法了
rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
rewrite ^/oj/(.*\.jsp)(/)(.*)$ /oj/$1?file=/$3 last;
access_log /log/nginx/moodle/access.log; #access_log属于ngx_http_log_module的设置, 缺省level为info
error_log /log/nginx/moodle/error.log; #error_log属于core module, 缺省的level是error
location / {
root /html/www;
index index.php index.html index.htm; #由于是PHP类型的动态页面为主,所以把index.php放在前面效率会更高些
# try_files $uri $uri/ /index.php?$args; #普通php网站因为没有rewrite的话,这个不需要
}
error_page 404 /404.html; #error_page errcode uri (也就是说出现了404错误,会请求/404.html)
location = /404.html { #这是一个典型的location
root /html/www;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /html/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# 这种写法可以防止把恶意程序伪装成.jpg之类的攻击,(其实有个更简单的方法,就是把php.ini中的cgi.fix_pathinfo=0,但有时候简单的修改cgi.fix_pathinfo会造成有的php脚本出错)
location ~ \.php$ {
root /html/www;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
#try_files $uri =404; #这个try_files说明:对于.php文件,直接执行$uri, 如果找不到这个$uri,直接给出404错误,(和 location / 定义不同!),主要是为了防止 伪装成图片的攻击 (目前看,最安全的方式,是用上面那一句话,官方推荐的)
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /nginx {
stub_status on;
access_log on;
}
location ~ \.flv$ {
flv;
limit_rate 250k;
}
location ~ \.mp4$ {
mp4;
limit_rate 250k;
}
location /app/ {
alias /local/tomcat/webapps/app/;
index Index.jsp index.jsp Index.html Index.htm ;
#proxy_redirect on;
proxy_set_header oisy.cn $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 30;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://127.0.0.1:8080;
}
location /ojj/{
# ajp_pass tomcat;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
参考:
Nginx配置性能优化
http://blog.youkuaiyun.com/xifeijian/article/details/20956605