nginx的web基础

基于nginx的web部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[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的压缩功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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

  设置显示目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   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  加载配置

  限制访问相应的速度

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

  

 

posted @   烟雨楼台,行云流水  阅读(162)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
点击右上角即可分享
微信分享提示