nginx的web基础

Posted rdchenxi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx的web基础相关的知识,希望对你有一定的参考价值。

基于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;

        }

  

 

以上是关于nginx的web基础的主要内容,如果未能解决你的问题,请参考以下文章

Web 基础——Nginx

Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error code(代码片段

Nginx Web 基础入门

Web 基础——Nginx

nginx基础教程——小白基础

nginx的web基础