IT俱乐部 Nginx Nginx中include的具体用法

Nginx中include的具体用法

include可以用在任何地方,前提是include的文件自身语法正确。
include文件路径可以是绝对路径,也可以是相对路径,相对路径以nginx.conf为基准,同时可以使用通配符。

配置实例

# 绝对路径
include /etc/conf/nginx.conf
# 相对路径
include port/80.conf
# 通配符
include *.conf

测试配置文件

> ./nginx -t 

主模式配置

user  wwwt;    # 服务器使用用户
worker_processes  1;    # 配置 worker 进程启动的数量,建议配置为 CPU 核心数
#error_log  logs/error.log;    # 全局错误日志
pid    /etc/nginx/logs/nginx.pid;     # 设置记录主进程 ID 的文件
events {
    # 单个后台 worker process 进程的最大并发链接数
    # 并发总数 max_clients = worker_professes * worker_connections
    worker_connections 4096;  ## Defaule: 1024
    # multi_accept on;  ## 指明 worker 进程立刻接受新的连接
}
# 主模式
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;
    # 重点,分文件放置路径
    include /etc/nginx/cs/*.conf;
    #gzip  on
    server {
        # the port your site will be served on
        listen 80;
        # the domain name it will serve for
        charset     utf-8;
        # max upload size
        client_max_body_size 75M;   # adjust to taste
        # Finally, send all non-media requests to the Django server.
        location / {
        }
    }
}

分文件

server {
    # the port your site will be served on
    listen 443;
    # the domain name it will serve for
    server_name  cs.oyz.cn; # substitute your machine's IP address or FQDN
    charset     utf-8;
    ssl   on;
    ssl_certificate      cert/*****.pem;
    ssl_certificate_key  cert/*****.key;
    # max upload size
    client_max_body_size 75M;   # adjust to taste
    # Django media
    location /media  {
        alias ********;  # your Django project's media files - amend as required
    }
    location /static {
        alias ********; # your Django project's static files - amend as required
    }
    location / {
        uwsgi_param UWSGI_SCHEME https;
        uwsgi_pass  127.0.0.1:9002;
        uwsgi_send_timeout 3600s;        # 指定向uWSGI传送请求的超时时间,完成握手后向    uWSGI传送请求的超时时间。
        uwsgi_connect_timeout 3600s;     # 指定连接到后端uWSGI的超时时间。
        uwsgi_read_timeout 3600s;        # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

到此这篇关于Nginx中include的具体用法的文章就介绍到这了,更多相关Nginx include内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/nginx/9232.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部