EduSoho网校系统安装教程(三):nginx配置

 


Ubuntu下nginx的配置:
安装nginx

sudo apt-get install nginx


配置Nginx

sudo vim /etc/nginx/nginx.conf
在http{}添加

client_max_body_size 1024M;
sendfile       on;


配置nginx的虚拟主机
sudo vim /etc/nginx/sites-enabled/edusoho

输入:
server {
    listen 80;

    # [改] 网站的域名
    server_name www.example.com example.com;
    
    #301跳转可以在nginx中配置

    # 程序的安装路径
    root /var/www/edusoho/web;

    # 日志路径
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location / {
        index app.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/udisk {
        internal;
        root /var/www/edusoho/app/data/;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        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=/var/www/edusoho/app/data/udisk;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 8 128k;
    }

    # 配置设置图片格式文件
    location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
        # 过期时间为3年
        expires 3y;
        
        # 关闭日志记录
        access_log off;

        # 关闭gzip压缩,减少CPU消耗,因为图片的压缩率不高。
        gzip off;
    }

    # 配置css/js文件
    location ~* \.(css|js)$ {
        access_log off;
        expires 3y;
    }

    # 禁止用户上传目录下所有.php文件的访问,提高安全性
    location ~ ^/files/.*\.(php|php5)$ {
        deny all;
    }

    # 以下配置允许运行.php的程序,方便于其他第三方系统的集成。
    location ~ \.php$ {
        # [改] 请根据实际php-fpm运行的方式修改
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS              off;
    }
}

sudo /etc/init.d/nginx restart


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;

}

 

你可能感兴趣的:(安装)