Nginx配置文件服務管理
cd /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.default
1,event 網絡模型的定義
event{
網絡定義模型
}
2,http的配置
http{
網站整體環境配置
server{ //--server--一個可以訪問的網站
一個可以訪問的web服務器 //--server--一般在這裏修改
} //--server--綁定虛擬主機,多加幾個server即可
}
3,配置文件詳情
[root@iZwz9h901rvv69020rk7fsZ conf]# vim nginx.conf
user www www;
#是nginx服務的僞用戶,僞用戶組
worker_processes auto;
#啓動進程,通常設置成cup數量相等,相當於cpu的個數
error_log /home/wwwlogs/nginx_error.log crit;
#錯誤日誌
pid /usr/local/nginx/logs/nginx.pid;
#主進程pid保存文件
google_perftools_profiles /tmp/tcmalloc;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
#文件描述符的數量
events
{
use epoll;
#網絡I/O模型
worker_connections 51200
#工作進程最大允許的連接數
}
http
{
include mime.types;
default_type application/octet-stream;
#設定mine類型,文件傳送類型由mine.type文件定義
server_names_hash_bucket_size 128;
#保存服務器名字的hash表大小
client_header_buffer_size 32k;
#客戶端請求頭部緩衝區大小
large_client_header_buffers 4 32k;
#最大客戶端頭緩衝大小
client_max_body_size 50m;
#客戶端最大上傳文件大小
sendfile on;
# 控制異步傳輸
tcp_nopush on;
# 控制異步傳輸
keepalive_timeout 60;
#連接超時時間
tcp_nodelay on;
#禁用nagle算法,就是不緩存數據
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
#fastcgi 設置,主要是提高了fastcgi性能
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#開啓gzip網絡壓縮
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
#隱藏版本號,報錯不會顯示版本,比價安全
access_log off;
#nginx日誌
server
{
listen 80 default_server;
#監聽端口
#listen [::]:80 default_server ipv6only=on;
server_name www.lnmp.org;
#域名
index index.html index.htm index.php;
#默認網頁文件名
root /data/www;
#網頁主目錄
#error_page 404 /404.html;
autoindex on
#開啓文件列表功能
include enable-php.conf;
#一下是nginx的網站核心配置,匹配等等,一般改動比較小
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
include vhost/*.conf;
}
4,虛擬主機
其實所謂綁定虛擬主機,就是在配置文件中加server
修改server中的server_name 域名
root 根目錄
注意:
爲了不讓主配置文件太雜太亂,專門加了一個vhost文件夾提供虛擬主機服務
可以在conf/vhost/下增加xxx(任意).conf文件單獨寫server來配置虛擬主機