Nginx更改conf配置文件的代码详解

 更新时间:2024年02月07日 11:36:17   作者:沙振宇  
本文主要介绍了Nginx如何更改conf配置文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作有一定的参考学习价值,需要的朋友们下面跟着小编来一起来学习吧

安装Nginx默认的配置文件路径:

/usr/local/nginx/conf/nginx.conf

默认的ngnix.conf:

user  nobody;
worker_processes  8;

pid         log/nginx.pid;
events {
    use epoll;
    worker_connections  100000;
}
worker_rlimit_nofile 100000;

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    sendfile          on;
    tcp_nopush        on;
    tcp_nodelay       on;
    keepalive_timeout  0;
    fastcgi_connect_timeout 30;
    fastcgi_send_timeout 30;
    fastcgi_read_timeout 30;
    fastcgi_buffer_size 1k;
    fastcgi_buffering off;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip              on;
    gzip_min_length   1k;
    gzip_buffers      4 16k;
    gzip_http_version 1.0;
    gzip_comp_level   2;
    gzip_types        text/plain application/x-javascript text/css application/xml text/javascript;
    gzip_vary         on;
    charset      utf-8;
    access_log   off;
    log_not_found off;

    error_page   400 403 405 408 /40x.html ;
    error_page   500 502 503 504 /50x.html ;
    server {
        listen       80;
        server_name  aaicourt.qcloud.com;
        client_max_body_size 100M;
        root /data/qcloud/proxy/www;
        access_log  /data/qcloud/proxy/log/weblog/access.log;
                error_log /data/qcloud/proxy/log/weblog/error.log;

        location / {
            index index.php index.html index.htm;
            if (-d $request_filename) {
                rewrite ^(/.*[^/])$ $1/index.php;
            }
        }
        rewrite ^/([a-zA-Z0-9]+)$ / last;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
                location ~ voice.cgi {
                        fastcgi_pass   127.0.0.1:3001;
                        fastcgi_index  index.cgi;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                }

                location ~ register.cgi {
                        fastcgi_pass   127.0.0.1:3002;
                        fastcgi_index  index.cgi;
                         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                         include        fastcgi_params;
                }

                location ~ inner.cgi {
                        fastcgi_pass   127.0.0.1:3003;
                        fastcgi_index  index.cgi;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  SERVER_NAME $http_host;
            include        fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_connect_timeout 600s;
            fastcgi_send_timeout 600s;
            fastcgi_read_timeout 600s;
        }
        location ~ /.svn/ {
            deny all;
        }
    }
}

我们现在开始更改,使此配置文件与更多的配置文件相关联。

主要是跟最后面的include有关,情况nginx.conf

user root;
worker_processes auto;
error_log /var/nginx/logs/error.log;
pid ./nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/nginx/logs/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    include /usr/local/nginx/conf/conf.d/*.conf;
}

其余的conf,我随便举个例子:

/usr/local/nginx/conf/conf.d

server {
    listen       80 default;
    server_name localhost;
    root /var/www/html/roboot/public/;
    index index.html index.php index.htm;

    access_log /var/log/nginx/ac_bot.log;
    error_log /var/log/nginx/err_bot.log;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png|ogg|ogv|svg|svgz|eot|otf|woff)(\?.+)?$ {
        expires max;
        log_not_found off;
    }
    server_tokens off;
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location / {
        index  index.php index.html;
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php last;
        }
    }
}

到此这篇关于Nginx更改conf配置文件的代码详解的文章就介绍到这了,更多相关Nginx更改conf配置文件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • nginx禁止某个IP访问站点的设置方法

    nginx禁止某个IP访问站点的设置方法

    近期发现博客遭到某些人的恶意灌水,频繁地利用发帖机器人发表评论,给博客的管理带来诸多不便,搜索了一下资料,可以利用nginx的ngx_http_access_module 模块设置允许/禁止哪些ip或ip段访问站点。
    2010-12-12
  • Nginx静态文件响应POST请求 提示405错误的解决方法

    Nginx静态文件响应POST请求 提示405错误的解决方法

    Apache、IIS、nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回“HTTP/1.1 405 Method not allowed”错误
    2013-04-04
  • nginx添加ssl模块的方法教程

    nginx添加ssl模块的方法教程

    这篇文章主要给大家介绍了关于nginx添加ssl模块的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习许吧。
    2017-12-12
  • Nginx基础学习之realip模块的使用方法

    Nginx基础学习之realip模块的使用方法

    这篇文章主要给大家介绍了关于Nginx基础学习之realip模块使用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Nginx具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2020-06-06
  • nginx status配置及参数配置小结

    nginx status配置及参数配置小结

    本文主要介绍了nginx status配置及参数配置,其实要监控Nginx的状态非常简单,它内建了一个状态页,只需修改Nginx配置启用Status即可,感兴趣的可以了解一下
    2024-04-04
  • 解读nginx反向代理location和proxy_pass的映射关系

    解读nginx反向代理location和proxy_pass的映射关系

    这篇文章主要介绍了解读nginx反向代理location和proxy_pass的映射关系,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-01-01
  • Nginx配置带SSL认证的转发方式 (HTTPS请求)

    Nginx配置带SSL认证的转发方式 (HTTPS请求)

    本文详细介绍了如何在Windows系统上安装和配置Nginx以支持HTTPS,首先,下载并解压Nginx和OpenSSL,并配置环境变量,然后,生成SSL证书和密钥文件,并在Nginx配置文件中启用SSL,最后,启动Nginx并访问配置的HTTPS路径以验证配置是否成功
    2026-01-01
  • Nginx中定义404页面并且返回404状态码的正确方法

    Nginx中定义404页面并且返回404状态码的正确方法

    这篇文章主要介绍了Nginx中定义404页面并且返回404状态码的正确方法,本文在一次AJAX调用时发现了这个问题,服务器返回了一个404页页但没有返回404状态码,需要的朋友可以参考下
    2014-08-08
  • Nginx记录分析响应慢的请求及替换网站响应内容的配置

    Nginx记录分析响应慢的请求及替换网站响应内容的配置

    这篇文章主要介绍了Nginx记录分析响应慢的请求及替换网站响应内容的配置,分别用到了ngx_http_log_request_speed模块和ngx_http_sub_module模块,需要的朋友可以参考下
    2016-01-01
  • 使用nginx方式实现http转换为https的示例代码

    使用nginx方式实现http转换为https的示例代码

    这篇文章主要介绍了使用nginx方式实现http转换为https的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-09-09

最新评论