nginx学习第三章

一、系统环境

ubuntu6.4系统

nginx 版本: nginx/1.10.3 (Ubuntu)。

二、打开目录浏览功能
Nginx默认是不允许列出整个目录的。如需此功能,编辑虚拟主机配置文件,在location server 或 http段中加入
autoindex on;
另外两个参数最好也加上去:
autoindex_exact_size off;
默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_localtime on;
默认为off,显示的文件时间为GMT时间。
改为on后,显示的文件时间为文件的服务器时间

三、修改nginx.conf配置

1、修改nginx配置文件

user root root;     # CGI scripts needs root permisions
worker_processes 2; # 2 workers should be enough
pid /run/nginx.pid;
worker_cpu_affinity 11110101 11111010;

error_log /dev/null crit;

events {
    worker_connections 1024;
    use epoll;
}

# rtmp module
#include rtmp.conf;

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    index index.html;
    
    server {
        # Logging Settings
        rewrite_log on;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        listen          80;
        server_name     localhost;
        access_log off;

        ## 浏览器访问目录参数
        autoindex on;   

        ## 设置启动目录
        root    /var/www/html;

        error_page 404 /404.html;
        location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /share;
        }
    }

}

如果本地的ip地址是192.168.4.1,在浏览器中输入http://192.168.4.1:80

如果Linux系统的/var/www/html目录下有index.html文件,则浏览器中显示index.html文件中的内容,否则显示目录下的文件

猜你喜欢

转载自www.cnblogs.com/carriezhangyan/p/11840935.html