美文网首页Java技术升华面试精选
Nginx include 主子配置文件

Nginx include 主子配置文件

作者: 承诺一时的华丽 | 来源:发表于2021-07-13 10:46 被阅读0次

注意root权限创建相关配置
1、创建conf目录

cd /etc/nginx/
mkdir conf

2、创建server配置文件

cd conf
touch doman.conf
  • 写入server部分配置内容
    server {
        listen       80;

        client_max_body_size   10m;
        gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";

        root /data/website/web;

        location / {
            try_files $uri $uri/ /index.html;
        }

        location /api {
            proxy_pass http://127.0.0.1:8080/api;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $host;
            proxy_set_header   X-Real-IP         $remote_addr;
        }
    }

3、nginx.conf中http下添加include配置

 include /etc/nginx/conf/*.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;

    include /etc/nginx/conf/*.conf;   # 配置

    server {
    ...

4、重启nginx服务

sudo systemctl restart nginx

相关文章

网友评论

    本文标题:Nginx include 主子配置文件

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