nginx配置,重啓,日誌查看

nginx系統配置文件

/etc/nginx/nginx.conf
在這文件的最下面添加具體工程的nginx.conf路徑.
nginx.conf

user  developer developer;
worker_processes  4;

#error_log  /var/log/nginx/error.log crit;
#error_log  /var/log/nginx/error.log notice;
#error_log  /var/log/nginx/error.log info;

pid /run/nginx.pid;

worker_rlimit_nofile 10240;
events {
    use epoll;
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size    128;
    client_max_body_size             16m;

    client_header_buffer_size        32k;
    large_client_header_buffers      4 64k;

    sendfile                         on;
    tcp_nopush                       on;
    tcp_nodelay                      on;

    #process life time(s)
    keepalive_timeout                60;

    #zip compress setting
    gzip_static                      on;
    gzip_min_length                  1k;
    gzip_http_version                1.1; 
    gzip_buffers                     4 8k;
    gzip_comp_level                  2;
    gzip_types                       text/plain application/x-javascript text/css application/xml;
    gzip_vary                        on; 
    gzip_disable                     "MSIE [1-6]\.";
    #limit_zone  crawler  $binary_remote_addr  10m;

    fastcgi_connect_timeout   300;
    fastcgi_read_timeout      300;
    fastcgi_send_timeout      300;
    fastcgi_intercept_errors   on; 

    fastcgi_buffer_size              64k;
    fastcgi_buffers                  4 64k;
    fastcgi_busy_buffers_size        128k;
    fastcgi_temp_file_write_size     128k;
    fastcgi_temp_path                /dev/shm;

    log_format  new_log  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log new_log;

#   include /home/testproject/nginx.conf;
    include /home/projectA/config/nginx.projectA.conf;
}

nginx工程文件

nginx.projectA.conf

    server {
          listen       80;
          server_name  projectA.com www.projectA.com www.test.projectA.com;
          rewrite ^/(.*)$ http://www.test.projectA.com/$1 last;
    }

    server {
        listen       80;
        server_name  www.projectA.com www.test.projectA.com
        index        index.php;
        root         /home/projectA/host;
        charset      utf-8;

        # Block
        location ~ /\.          { access_log off; log_not_found off; deny all; }
        location ~ /.*\.sql.*$  { access_log off; log_not_found off; deny all; }
        location ~ /.*\.mwb.*$  { access_log off; log_not_found off; deny all; }
        location ~ /.*\.mgt.*$  { access_log off; log_not_found off; deny all; }
        location ~ /.*\.conf.*$ { access_log off; log_not_found off; deny all; }

        location = /robots.txt  { access_log off; log_not_found off; allow all; }
        location = /search.xml  { access_log off; log_not_found off; allow all; }
        location = /favicon.ico { access_log off; log_not_found off; expires max; }

        #Publishing
        location ~* ^/publishing {
            root /home/projectA;
        }

        #Service
        location / {
            index index.php;
            if (!-f $request_filename) {
                rewrite ^(.*) /index.php?$1 last;
            }
        }

        location ~ \.php$ {
            fastcgi_keep_conn     on;
            fastcgi_pass          127.0.0.1:9001;
            fastcgi_index         index.php;
            fastcgi_param         SCRIPT_FILENAME /home/projectA/host/index.php;
            #fastcgi_param        COUNTRY $geoip_country_code;
            include               fastcgi_params;
        }

        # Cache static files for as long as possible
        location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
            expires max; log_not_found off; access_log off;
        }
    }   

配置文件修改後,重啓nginx(一定要用root執行)

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload(也可以使用service nginx restart)
ps -aux | grep nginx

nglnx日誌查看

cat /var/log/nginx/error.log
cat /var/log/nginx/access.log

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章