看在nginx使用之前

1.启动方式

To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

nginx -s signal
Where signal may be one of the following:

stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files


Serving Static Content
An important web server task is serving out files (such as images or static HTML pages). You will implement an example where, depending on the request, files will be served from different local directories: /data/www (which may contain HTML files) and /data/images (containing images). This will require editing of the configuration file and setting up of a server block inside the http block with two location blocks.
First, create the /data/www directory and put an index.html file with any text content into it and create the /data/images directory and place some images in it.


2.选择location匹配的策略

If there are several matching location blocks nginx selects the one with the longest prefix.

When nginx selects a location block to serve a request it first checks location directives that specify prefixes, remembering location with the longest prefix, and then checks regular expressions. If there is a match with a regular expression, nginx picks this location or, otherwise, it picks the one remembered earlier.


server {
    location / {
        proxy_pass http://localhost:8080/;
    }


    location ~ \.(gif|jpg|png)$ {
        root /data/images;
    }
}


3.默认模块



4.如何选择底层connection驱动方式

On platforms that support several methods nginx will normally select the most efficient method automatically. However, if needed, a connection processing method can be selected explicitly with the use directive.


5.debug方式

error_log /path/to/log debug;
http {
    server {
        error_log /path/to/log debug;
        ...

error_log memory:32m debug;


6.nginx选择server的方式

6.1 基于host选择server

In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour. It can also be set explicitly which server should be default, with the default_server parameter in the listen directive:


server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}


6.2 选择server的顺序

When searching for a virtual server by name, if name matches more than one of the specified variants, e.g. both wildcard name and regular expression match, the first matching variant will be chosen, in the following order of precedence:
  • exact name
  • longest wildcard name starting with an asterisk, e.g. “*.example.org”
  • longest wildcard name ending with an asterisk, e.g. “mail.*”
  • first matching regular expression (in order of appearance in a configuration file)

6.3 server的写法

Wildcard names

A wildcard name may contain an asterisk only on the name’s start or end, and only on a dot border. The names “www.*.example.org” and “w*.example.org” are invalid.

Miscellaneous names

There are some server names that are treated specially.
If it is required to process requests without the “Host” header field in a server block which is not the default, an empty name should be specified:
server {
    listen       80;
    server_name  example.org  www.example.org  "";
    ...
}

catch-all

In catch-all server examples the strange name “_” can be seen:
server {
    listen       80  default_server;
    server_name  _;
    return       444;
}

6.4 针对server_name 过长的两个参数

could not build the server_names_hash,
you should increase server_names_hash_bucket_size: 32
could not build the server_names_hash,
you should increase either server_names_hash_max_size: 512

7.负载均衡

负载均衡
http {
    upstream myapp1 {
        ()| least_conn | ip_hash
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }


    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}


负载的更多配置 http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值