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;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EduSoho资讯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值