【操作系统】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;
        }
    }
}
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
同一ip(都是80端口)可以绑定无数个域名 配置简单 里面包含一个配置文档:配置文档.doc 看一遍 大部分人都会设置了。 内容如下: NGNIX配置文档 1.解压文件到相应文件夹下(我解压到D:/下) (这里是图片) 目录结构如上 2.在D:\nginx\目录下用记事本新建一个文本文档改名为 proxy.conf。 proxy.conf里面的内容格式如下: server { listen 80; server_name www.*****.com; location / { proxy_pass http://192.168.45.1:8045; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } (完整拷贝上面的内容server_name www.*****.com; 这里面的域名即是来访域名 proxy_pass http://192.168.45.1:8045; 这里面的域名(http://192.168.45.1:8045)即是内部跳转的地址,将该内容拷贝多份实现不同来访域名的跳转) 如下: 3.找到D:\nginx\confnginx.conf文件用记事本打开 在文段末尾大括号前加上 include proxy.conf;(就是加载刚刚新建的那个文件(注意路径)) 4.进入cmd 进入D盘: d: 进到nginx文件夹下:cd nginx 启动nginx.exe:start nginx Cmd窗口会闪一下 进程里面会多了个 浏览器里面输入:http://127.0.0.1 将出现: Nginx的欢迎界面。 注: nginx -s stop // 停止nginx nginx -s reload // 重新加载配置文件 nginx -s quit // 退出nginx nginx-1.3.9.zip(这个版本) (1分钟搞定只是夸张说法啦,给你增加信心的啦,真正的操作起来,因人而异,没搞定的耐心再试试,自己xp系统亲测成功,不喜欢的无拍砖哦,实在搞不定的加我qq852208555 一起研究下 谢谢!)

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沙振宇

你的鼓励将是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值