CentOS利用Nginx搭建下载功能服务器

 更新时间:2017年06月23日 23:43:46   投稿:mdxy-dxy  
这篇文章主要介绍了CentOS利用Nginx搭建下载功能服务器,需要的朋友可以参考下

利用nginx在服务器搭建下载功能,

安装Nginx,pcre
mkdir /usr/local/nginx
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12
./configure --prefix=/usr/local/pcre
make && make install
tar zxvf nginx-1.0.12.tar.gz

tar zxvf nginx-1.0.12.tar.gz
cd nginx-1.0.12
./configure --prefix=/usr/local/nginx/ --with-pcre=/opt/pcre-8.12
make && make install
vi /usr/local/nginx/conf/nginx.conf

#user www www;
worker_processes 8;
error_log /usr/local/nginx/logs/error.log crit;
pid    /usr/local/nginx/logs/nginx.pid;
 
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 010000
00 10000000;
worker_rlimit_nofile 51200;
 
events {
    use epoll;
    worker_connections 51200;
}
 
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 8m;
  access_log off;
  sendfile on;
  tcp_nodelay on;
  tcp_nopush   on;
  keepalive_timeout 30;
 
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 32k;
  fastcgi_buffers 8 32k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 256k;
  fastcgi_intercept_errors on;
  open_file_cache max=51200 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 1;
 
  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;
  #if you modify nginx source,please hidden follow
  #server_tokens off;
  log_format access '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    include     /usr/local/nginx/conf/vhost/*.conf;
}

虚拟主机配置

mkdir /usr/local/nginx/conf/vhost
cd /usr/local/nginx/conf/vhost
vi hosts.conf

server {
  listen    80;
  server_name 42.62.XX.
  index index.html index.htm index.php;
  root /game/;
 
 
  error_page 502 = /502.html;
  location ~* ^/upload/.*\.(php|php5)$ {
          deny all;
  }
#  location ~ .*\.(php|php5)?$ {
#        #fastcgi_pass unix:/tmp/php-cgi.sock;
#    fastcgi_pass 127.0.0.1:9000;
#    fastcgi_index index.php;
#    include fastcgi.conf;
#  }
 
 
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ {
    expires   30d;
  }
 
  location ~ .*\.(js|css)?$ {
    expires   12h;
  }
#access_log /data/webroot/nginx/logs/access.log access;
#error_log /data/webroot/nginx/logs/error.log error;
}

#/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful

#/usr/local/nginx/sbin/nginx -s reload

此时在服务器上创建 /game 目录, 把需要被下载的资源放目录里面就可以了。

相关文章

  • Nginx 配置 HTTPS的详细过程

    Nginx 配置 HTTPS的详细过程

    这篇文章主要介绍了Nginx 配置 HTTPS 完整过程,包括nginx 的 ssl 模块安装,ssl 证书部署,nginx.conf 配置,重启 nginx无信息提示就成功啦,本文给大家介绍的非常详细,需要的朋友可以参考下
    2022-05-05
  • 使用nginx缓存服务器上静态文件的设置方法

    使用nginx缓存服务器上静态文件的设置方法

    这篇文章主要介绍了使用nginx缓存服务器上的静态文件,文中给大家提到了nginx缓存的优点及设置方法,通过实例相结合的形式给大家介绍的非常详细,需要的朋友可以参考下
    2018-05-05
  • nginx模块stream配置的具体使用

    nginx模块stream配置的具体使用

    stream模块一般用于tcp/UDP数据流的代理和负载均衡,可以通过stream模块代理转发TCP消息,本文主要介绍了nginx模块stream配置的具体使用,感兴趣的可以了解一下
    2023-10-10
  • 使用 Nginx 部署静态页面的方法

    使用 Nginx 部署静态页面的方法

    本篇文章主要介绍了使用 Nginx 部署静态页面的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-06-06
  • Nginx+Tomcat搭建高性能负载均衡集群的实现方法

    Nginx+Tomcat搭建高性能负载均衡集群的实现方法

    这篇文章主要介绍了Nginx+Tomcat搭建高性能负载均衡集群的实现方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-03-03
  • nginx: [warn]

    nginx: [warn] "log_format" directive used only on "http" lev

    这篇文章主要介绍了nginx: [warn] "log_format" directive used only on "http" level 解决方法,需要的朋友可以参考下
    2014-08-08
  • Nginx反向代理多域名的HTTP和HTTPS服务的实现

    Nginx反向代理多域名的HTTP和HTTPS服务的实现

    这篇文章主要介绍了Nginx反向代理多域名的HTTP和HTTPS服务的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-06-06
  • Nginx HTTPS实现原理及配置实践

    Nginx HTTPS实现原理及配置实践

    本文主要介绍了Nginx HTTPS实现原理及配置实践,详细的介绍了HTTPS原理,实现及其HTTPS单台配置实践,集群配置、优化等,具有一定的参考价值,感兴趣的可以了解一下
    2023-09-09
  • 使用nginx+二级域名+https支持

    使用nginx+二级域名+https支持

    这篇文章主要介绍了使用nginx+二级域名+https支持,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-05-05
  • 服务器报错nginx 502 Bad Gateway的原因及如何解决详解

    服务器报错nginx 502 Bad Gateway的原因及如何解决详解

    项目启动时莫名其妙网站访问不了,502 Bad Gateway,下面这篇文章主要给大家介绍了关于服务器报错nginx 502 Bad Gateway的原因及如何解决的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2023-06-06

最新评论