基于 nginx 的 web 部署
- [[email protected] ~]# cd /data/Web/
- client_body_temp/ conf/ fastcgi_temp/ html/ logs/ proxy_temp/ scgi_temp/ uwsgi_temp/
- [[email protected] ~]# cd /data/Web/
- [[email protected] Web]# mkdir chenxi
- [[email protected] Web]# echo "chenxi"> c
- chenxi/ client_body_temp/ conf/
- [[email protected] Web]# echo "chenxi"> chenxi/index.HTML 创建网页默认网页
- [[email protected] Web]# VIM conf/nginx.conf
- http {
- include 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 logs/access.log main;
- sendfile on;
- tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #gzip on;
- server {
- # 监听的 IP 及端口
- listen 8080;
- # 虚拟主机对硬解析的主机名
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- # 所有的此虚拟主机匹配的请求都到 chenxi 此网页目录下
- location / {
- alias chenxi/;
- index index.HTML index.htm;
- }
- }
- [[email protected] Web]# nginx -t
- nginx: the configuration file /data/Web/conf/nginx.conf syntax is ok
- nginx: configuration file /data/Web/conf/nginx.conf test is successful
- [[email protected] Web]# nginx
打开 nginx 的压缩功能
- http {
- include 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 logs/access.log main;
- sendfile on;
- tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- #打开 gzip 压缩功能
- gzip on;
- #小于多少字节就不压缩了, 小于 1k 就压缩
- gzip_min_length 1;
- #设置压缩级别, 压缩级别, 1-10, 数字越大压缩的越好, 时间也越长, 看心情随便改吧
- gzip_comp_level 2;
- #进行压缩的文件类型, 缺啥补啥就行了, JavaScript 有两种写法, 最好都写上吧, 总有人抱怨 JS 文件没有压缩, 其实多写一种格式就行了
- gzip_types text/plain application/x-JavaScript text/CSS application/xml text/JavaScript application/x-httpd-PHP image/jpeg image/gif image/PNG;
- #跟 Squid 等缓存服务有关, on 的话会在 Header 里增加 "Vary: Accept-Encoding", 我不需要这玩意, 自己对照情况看着办吧
- gzip_vary off;
- #IE6 对 Gzip 不怎么友好, 不给它 Gzip 了
- gzip_disable "MSIE [1-6]\.";
- server {
- #监听的 IP 及端口
- listen 8080;
- #虚拟主机对硬解析的主机名
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #所有的此虚拟主机匹配的请求都到 chenxi 此网页目录下
- location / {
- alias chenxi/;
- index index.HTML index.htm;
- }
- [[email protected] Web]# nginx -t
- nginx: the configuration file /data/Web/conf/nginx.conf syntax is ok
- nginx: configuration file /data/Web/conf/nginx.conf test is successful
- [[email protected] Web]# nginx -s reload
设置显示目录结构
- server {
- #监听的 IP 及端口
- listen 8080;
- #虚拟主机对硬解析的主机名
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- #所有的此虚拟主机匹配的请求都到 chenxi 此网页目录下
- location / {
alias /etc/; 把 / etc 目录挂出去
autoindex on; 显示 etc 目录结构
- # index index.HTML index.htm;
- }
- [[email protected] Web]# nginx -t
- nginx: the configuration file /data/Web/conf/nginx.conf syntax is ok
- nginx: configuration file /data/Web/conf/nginx.conf test is successful
- [[email protected] Web]# nginx -s reload 加载配置
限制访问相应的速度
- location / {
- alias chenxi/;
set $limit_rate 1k; 表示 1 毫秒向浏览器传出一字节的数据
- #autoindex on;
- # index index.HTML index.htm;
- }
来源: http://www.bubuko.com/infodetail-3077400.html