基于nginx的web部署

[root@nginx ~]# cd /data/web/
client_body_temp/ conf/ fastcgi_temp/ html/ logs/ proxy_temp/ scgi_temp/ uwsgi_temp/
[root@nginx ~]# cd /data/web/
[root@nginx web]# mkdir chenxi
[root@nginx web]# echo "chenxi" > c
chenxi/ client_body_temp/ conf/
[root@nginx web]# echo "chenxi" > chenxi/index.html 创建网页默认网页
[root@nginx 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;
}
}
[root@nginx 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
[root@nginx 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;
}
[root@nginx 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
[root@nginx 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;
}
[root@nginx 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
[root@nginx web]# nginx -s reload 加载配置

  限制访问相应的速度

  location / {
alias chenxi/;
set $limit_rate 1k; 表示1毫秒向浏览器传出一字节的数据
#autoindex on;
# index index.html index.htm; }

  

05-11 15:37