美文网首页
nginx第一眼

nginx第一眼

作者: AndyDennisRob | 来源:发表于2020-04-16 19:10 被阅读0次

下载软件.zip

nginx官网下载

项目结构

主要是改nginx.conf.先来看看项目的结构.圈起来的是我新建的,大家不必着急。


项目结构

主要文件

nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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 {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /test{
            alias dlib/;
            index test.html;
        }
        error_page  404              /404.html;
        location =/ 404.html{
            root html;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}



404.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>div404</title>
    <style>
        body{
            text-align: center;
            font-size: 30px;
            color: blueviolet;
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
    <h1>Sorry ,404 error!</h1>
</body>
</html>



test.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx</title>
    <style>
        body{
            text-align: center;
            font-size: 30px;
            color: blueviolet;
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
    <div class="">
        <h1>test</h1>
    </div>
</body>
</html>



运行结果

根目录 test目录 404错误

结束语

这只是我们小试nginx,其实呢关于nginx还有很多知识,希望大家课后自行学习。这里有之前录制的nginx视频,中途有个地方说不清楚也推荐一个博客[alias和root区别](# Nginx虚拟目录alias和root目录
其实笔者个人觉得只要记住下面这个就ok了。遇到具体的情况再去查资料就ok了。

博客截图
感谢大家观看。

相关文章

网友评论

      本文标题:nginx第一眼

      本文链接:https://www.haomeiwen.com/subject/cibdvhtx.html