EduSoho部署(centos+nginx)

2018年11月12日 Off By yyy

Centos 6.5配置nginx

安装和配置nginx
yum install nginx

#启动
service nginx start

#设为开机启动
chkconfig nginx on

#配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables

#(允许80端口通过防火墙)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
#(允许3306端口通过防火墙)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

保存后重启防火墙:

/etc/init.d/iptables restart #重启防火墙使配置生效

配置Nginx

vi /etc/nginx/nginx.conf

在http{}配置中加入:

client_max_body_size 1024M;

vi /etc/nginx/conf.d/edusoho.conf

加入以下配置:

server {

listen 80;

server_name www.centos.edu;

root /usr/share/nginx/edusoho/web;

access_log /var/log/nginx/edusoho.access.log;

error_log /var/log/nginx/edusoho.error.log;

location / {

index app.php;

try_files $uri @rewriteapp;

}

location @rewriteapp {

rewrite ^(.*)$ /app.php/$1 last;

}

location ~ ^/udisk {

internal;

root /usr/share/nginx/edusoho/app/data/;

}

location ~ ^/(app|app_dev)\.php(/|$) {

fastcgi_pass 127.0.0.1:9000;

fastcgi_split_path_info ^(.+\.php)(/.*)$;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param HTTPS off;

fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;

fastcgi_param HTTP_X-Accel-Mapping /udisk=/usr/share/nginx/edusoho/app/data/udisk;

fastcgi_buffer_size 128k;

fastcgi_buffers 8 128k;

}

location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {

expires 3y;

access_log off;

gzip off;

}

location ~* \.(css|js)$ {

access_log off;

expires 3y;

}

location ~ ^/files/.*\.(php|php5)$ {

deny all;

}

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_split_path_info ^(.+\.php)(/.*)$;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param HTTPS off;

include fastcgi_params;

}

}

/etc/init.d/nginx restart #重启nginx

301跳转
server_name www.centos.edu; centos.edu;
目的:把 centos.edu跳转到www.centos.edu 方法如下:
if ($host = “centos.edu” ) {
rewrite ^/(.*)$ http://www.centos.edu/$1 permanent;

}