一、nginx.conf的配置方式,创建新vhost
1)nginx的安装编译方式
./configure --prefix=/opt/nginx --user=nginx --group=nginx --conf-path=/opt/nginx/conf/nginx.conf --error-log-path=/opt/nginx/log/error.log --http-log-path=/opt/nginx/log/access.log --http-client-body-temp-path=/opt/nginx/client/ --http-proxy-temp-path=/opt/nginx/proxy/ --http-fastcgi-temp-path=/opt/nginx/fcgi/ --http-uwsgi-temp-path=/opt/nginx/uwsgi --http-scgi-temp-path=/opt/nginx/scgi --with-pcre --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --pid-path=/opt/nginx/nginx.pid --with-file-aio --with-http_image_filter_module --add-module=/opt/nginx_upstream_check_module-master # 健康检查的模块 --with-stream # tcp 协议的模块
常用优化配置

user nginx; worker_processes 4; worker_cpu_affinity 00000001 00000010 00000100 00001000; worker_rlimit_nofile 204800; pid /var/run/nginx.pid; events { worker_connections 204800; use epoll; multi_accept off; } http { include /usr/local/nginx/conf/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 mtr '$remote_addr [$time_local] "$request_uri" ' '$status "$http_referer" ' '"$http_user_agent" "$host"'; sendfile on; keepalive_timeout 30; client_header_timeout 30; client_body_timeout 40; server_tokens off; tcp_nodelay on; gzip on; include /usr/local/nginx/conf/vhost/*.conf; fastcgi_send_timeout 300; fastcgi_read_timeout 300; #fastcgi_buffer_size 16k; #fastcgi_buffers 16 16k; #fastcgi_busy_buffers_size 16k; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 100k; open_file_cache max=51200 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 1; }
之后新的服务写入vhost文件夹
1.1)配置2

#user nginx; worker_processes auto; worker_rlimit_nofile 102400; events { use epoll; worker_connections 10240; accept_mutex off; } http { server_tokens off; include /usr/local/nginx/conf/mime.types; # default_type text/html; charset UTF-8; #log config log_format main '$remote_addr [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_x_forwarded_for" ' '"$request_time"'; sendfile on; tcp_nopush on; tcp_nodelay on; client_header_buffer_size 1024k; #timeout config keepalive_timeout 65; client_header_timeout 10; client_body_timeout 10; client_max_body_size 20m; reset_timedout_connection on; send_timeout 10; #limit_conn_zone $binary_remote_addr zone=addr:5m; #limit_conn addr 100; #gzip config gzip on; gzip_disable "msie6"; gzip_proxied any; gzip_min_length 1000; gzip_comp_level 6; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; open_file_cache max=100000 inactive=600s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors off; include /usr/local/nginx/vhost/conf/*.conf; # include /etc/nginx/sites-enabled/*; }
2)nginx的开机自启动脚本

#!/bin/bash # [ -e $PID ] -e 存在 PROCESS=/usr/local/nginx/sbin/nginx PID=/var/run/nginx.pid start(){ if [ -e $PID ];then echo -e "