Nginx站点搭建和自定义日志文件

来源:互联网 发布:SQL数据库怎样设置主键 编辑:程序博客网 时间:2024/04/29 14:55

一、Nginx.conf 配置多个server

1)./usr/local/nginx/conf/ 下创建 vhosts 目录

 [root@localhost vhost]# pwd
/usr/local/nginx/conf/vhost

2).在 /usr/local/nginx/conf/vhost里创建一个名字为 www.ap.net.conf 的文件,把以下内容拷进去

[root@localhost vhost]# ls
www.ap.net.conf

server {    listen      80;    server_name www.ap.net;access_log  /data/AP/logs/ap_access.log  access;error_log  /data/AP/logs/ap_error.log  crit;error_page   500 502 503 504  /50x.html;   <span style="white-space:pre"></span>location / {root    /data/AP/test;        index   index.html;    }    location = /50x.html {            root   /usr/local/nginx/html;            }    location ~* \.(gif|jpg|png)$ {        expires 30d;    }}
3).打开 /usr/local/nginx/conf/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来

#user  nobody;worker_processes  8;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}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"';    log_format access '$remote_addr $remote_user "$time_local" $request'                    '$status $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;    server {        listen       80;        server_name  channel.hzins.com;        #charset koi8-r;        #access_log  logs/host.access.log  main;        #java服务对应的站点配置location /api {            proxy_pass      http://127.0.0.1:8081;            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;        }location /test {                    root        /data/AP;                    index   index.html;        }        location / {            root   html;            index  index.html index.htm;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }# 包含所有的虚拟主机的配置文件include /usr/local/nginx/conf/vhost/*.conf;}

4).重启 Nginx    

service nginx restart

二、Nginx程序自定义日志文件

1).在Nginx.conf中注释/去掉原先存在的日志,并且添加新的日志格式:



2)在*.conf中自定义日志目录


3).重启Nginx

service nginx restart


备注:Nginx版本:

nginx/1.4.7

参考文献:

http://www.vpsee.com/2009/06/nginx-virtual-hosting-configuration/

http://blog.openlg.net/index.php/archives/266

http://www.linuxidc.com/Linux/2014-12/110989.htm


0 0
原创粉丝点击