nginx+mysql怎么配置服务端

小编给大家分享一下nginx + MySQL怎么配置服务端,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

创新互联建站从2013年开始,是专业互联网技术服务公司,拥有项目成都做网站、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元永泰做网站,已为上家服务,为永泰各地企业和个人服务,联系电话:13518219792

#双核CPU
user  nobody;
worker_processes 4 ;
worker_cpu_affinity 0001 0010 0100 1000 ;
worker_rlimit_nofile 65535;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    use   epoll;             #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能	
    multi_accept on;
    worker_connections 2048 ;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    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/log/nginx/access.log  main;
    #tcp_nopush     on;
    tcp_nopush on;
    tcp_nodelay on;
    access_log off;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;
   

    keepalive_timeout  65;#超时时间
    client_header_buffer_size 4k;#客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置
    open_file_cache max=102400 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;

    gzip on;
    gzip_disable "msie6";
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 4;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
   
    #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
    
	
   
   
     include /etc/nginx/conf.d/*.conf;
}
server {
    listen       80;
    server_name  www.test.com.cn test.com.cn;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /www/www/test;
        index  index.html index.htm index.php;
        autoindex off;
    }

    #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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
   location ~* ^/(attachment|static|images)/.*.(php|php5)$ {
    	deny all;
   }
	location ~* ^/addons/ewei/(static|images|data|cert)/.*.(php|php5)$ {
       		deny all;
 	  }
     location ~ \.php$ {
            root           /www/www/test;
            fastcgi_pass   127.0.0.1:9000;
	    #fastcgi_pass unix:/dev/shm/fpm-cgi.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
     {
        expires       15d;
     }
     location ~ .*\.(js|css)?$
     {
        expires       1d;
     }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Myssql5.7 配置

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
slow_query_log=ON
long_query_time=1
slow_query_log_file = /var/log/mysql/mysql-slow.log

general_log_file=/var/log/mysql/mysql-general-log.log
general_log = OFF
#避免Mysql的外部锁定,减少出错几率,增强稳定性:
skip-external-locking
#如果是1,那么查询总是先到查询缓存中查找,即使使用了sql_no_cache仍然查询缓存,因为sql_no_cache只是不缓存查询结果,而不是不使用查询结果。
query_cache_type=1
#back_log参数的值指出在MySQL暂时停止响应新请求之前,短时间内的多少个请求可以被存,在对堆栈中,如果系统短时间内有很多连接,则需>要增大该参数的值,该参数值指定到来的TCP/IP连接的监听队列的大小。不同的操作系统在这个队列的大小有自己的限制,将back_log设定得高于操作系统的限制将是无效的,其默认值为50,对于LINUX系统而言,推荐设置为小于512的整数:
back_log=100
binlog_cache_size=64M
#索引缓冲区大小,增加它可得到更好的索引处理性能,对于内存在4GB左右的服务器,该参数可设置为256M或384M。如果该参数值设置的过大>反而会使服务器的整体效率降低:
key_buffer_size=512M
#设定在网络传输中一次消息传输量的最大值,系统默认值为1MB,最大值是1GB,必须设定为1024的倍数,单位为字节:
max_allowed_packet=64M
#设置MySQL每个线程的堆栈大小,默认值足够大,可满足普通操作。可设置范围为128KB至4GB,默认192K:
thread_stack=64M
sort_buffer_size=64M
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache=256
max_heap_table_size=16M
#设置Thread Cache池中可以缓存的连接池线程最大数量,可设置为0-16384,默认为0。1GB内存我们配置为8,2GB内存我们配置为16,4GB或4GB以上内在我们配置为64:
thread_cache_size=64
#指定Mysql查询缓冲区的大小,可以通过在Mysql控制台观察,如果Qcache_lowmem_prunes的值非常大,则表明经常出现缓冲不够的情况,如果 Qcache_hits的值非常大,则表明查询缓冲使用的非常频繁 :
query_cache_size=64M
query_cache_limit=64M
#设置内在临时表最大值,如果超过该值,则会将临时表写入磁盘,其范围为1KB至4GB:
tmp_table_size=64M
#指定一个请求的最大连接时间,对于4GB左右内在的服务器来说,可以将其设置为5-10:
wait_timeout=20
#开启该选项可以彻底关闭MYSQL的TCP/IP连接方式,如果WEB服务器是以远程连接的方式访问MYSQL的数据库服务器,则不要开启该选项,否则>将无法正常连接。 skip-networking   抱怨Innodb比MyISAM慢 100倍?那么你大概是忘了调整这个值。默认值1的意思是每一次事务提交或事务外的指令都需要把日志写入(flush) 硬盘,这是很费时的。特别是使用电池供电缓存(Battery backed up cache)时。设成2对于很多运用,特别是从MyISAM表转过来的是可以的>,它的意思是不写入硬盘而是写入系统缓存。日志仍然会每秒flush到硬 盘,所以你一般不会丢失超过1-2秒的更新。设成0会更快一点,但安>全方面比较差,即使MySQL挂了也可能会丢失事务的数据。而值2只会在整个操作系#统 挂了时才可能丢数据:
innodb_flush_log_at_trx_commit=2
#这是 InnoDB 存储引擎的事务日志所使用的缓冲区。类似于 Binlog Buffer,InnoDB 在写事务日志的时候,为了提高性能,也是先将信息写>入 Innofb Log Buffer 中,当满足 innodb_flush_log_trx_commit 参数所设置的相应条件(或者日志缓冲区写满)之后,才会将日志写到文>件(或者同步到磁盘)中。可以通过 innodb_log_buffer_size 参数设置其可以使用的最大内存空间:
innodb_log_buffer_size=64M

innodb_buffer_pool_size=64M

innodb_log_file_size=1G

innodb_file_per_table=1

innodb_read_io_threads=10

innodb_write_io_threads=10

innodb_flush_method=O_DIRECT

innodb_io_capacity=1000

innodb_io_capacity_max=1000

innodb_lru_scan_depth=500

innodb_thread_concurrency=0  

innodb_autoinc_lock_mode=2

innodb_log_files_in_group=3

innodb_max_dirty_pages_pct=90

innodb_lock_wait_timeout=100

bulk_insert_buffer_size = 16M  

innodb_thread_concurrency = 8
innodb_purge_threads = 1
#tmp_table_size 的默认大小是 32M。如果一张临时表超出该大小,MySQL产生一个 The table tbl_name is full 形式的错误,如果你做很多 #高级 GROUP BY 查询,增加 tmp_table_size 值:
tmp_table_size=512M
#随机读取数据缓冲区使用内存(read_rnd_buffer_size):和顺序读取相对应,当 MySQL 进行非顺序读取(随机读取)数据块的时候,会利用>这个缓冲区暂存读取的数据。如根据索引信息读取表数据,根据排序后的结果集与表进行Join等等。总的来说,就是当数据块的读取需要满足>一定的顺序的情况下,MySQL 就需要产生随机读取,进而使用到 read_rnd_buffer_size 参数所设置的内存缓冲区:
read_rnd_buffer_size=128M
#默认配置没开查询缓存:
explicit_defaults_for_timestamp
#需要记录进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项:
binlog-do-db=dbname
#不需要记录进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项  :
binlog-ignore-db=dbname
#过滤掉一些没什么大问题的错误:
slave-skip-errors=all
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
host=localhost
user=mysqlback
password='password'

看完了这篇文章,相信你对“nginx + mysql怎么配置服务端”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


当前题目:nginx+mysql怎么配置服务端
本文链接:http://pwwzsj.com/article/pscghe.html