nginx+mysql怎么配置服務(wù)端

小編給大家分享一下nginx + MySQL怎么配置服務(wù)端,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

創(chuàng)新互聯(lián)建站從2013年開(kāi)始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元永泰做網(wǎng)站,已為上家服務(wù),為永泰各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話: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是多路復(fù)用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上內(nèi)核,可以大大提高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;#超時(shí)時(shí)間
    client_header_buffer_size 4k;#客戶端請(qǐng)求頭部的緩沖區(qū)大小,這個(gè)可以根據(jù)你的系統(tǒng)分頁(yè)大小來(lái)設(shè)置
    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;
   
    #壓縮類型,默認(rèn)就已經(jīng)包含text/html,所以下面就不用再寫(xiě)了,寫(xiě)上去也不會(huì)有問(wèn)題,但是會(huì)有一個(gè)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的外部鎖定,減少出錯(cuò)幾率,增強(qiáng)穩(wěn)定性:
skip-external-locking
#如果是1,那么查詢總是先到查詢緩存中查找,即使使用了sql_no_cache仍然查詢緩存,因?yàn)閟ql_no_cache只是不緩存查詢結(jié)果,而不是不使用查詢結(jié)果。
query_cache_type=1
#back_log參數(shù)的值指出在MySQL暫時(shí)停止響應(yīng)新請(qǐng)求之前,短時(shí)間內(nèi)的多少個(gè)請(qǐng)求可以被存,在對(duì)堆棧中,如果系統(tǒng)短時(shí)間內(nèi)有很多連接,則需>要增大該參數(shù)的值,該參數(shù)值指定到來(lái)的TCP/IP連接的監(jiān)聽(tīng)隊(duì)列的大小。不同的操作系統(tǒng)在這個(gè)隊(duì)列的大小有自己的限制,將back_log設(shè)定得高于操作系統(tǒng)的限制將是無(wú)效的,其默認(rèn)值為50,對(duì)于LINUX系統(tǒng)而言,推薦設(shè)置為小于512的整數(shù):
back_log=100
binlog_cache_size=64M
#索引緩沖區(qū)大小,增加它可得到更好的索引處理性能,對(duì)于內(nèi)存在4GB左右的服務(wù)器,該參數(shù)可設(shè)置為256M或384M。如果該參數(shù)值設(shè)置的過(guò)大>反而會(huì)使服務(wù)器的整體效率降低:
key_buffer_size=512M
#設(shè)定在網(wǎng)絡(luò)傳輸中一次消息傳輸量的最大值,系統(tǒng)默認(rèn)值為1MB,最大值是1GB,必須設(shè)定為1024的倍數(shù),單位為字節(jié):
max_allowed_packet=64M
#設(shè)置MySQL每個(gè)線程的堆棧大小,默認(rèn)值足夠大,可滿足普通操作??稍O(shè)置范圍為128KB至4GB,默認(rèn)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
#設(shè)置Thread Cache池中可以緩存的連接池線程最大數(shù)量,可設(shè)置為0-16384,默認(rèn)為0。1GB內(nèi)存我們配置為8,2GB內(nèi)存我們配置為16,4GB或4GB以上內(nèi)在我們配置為64:
thread_cache_size=64
#指定Mysql查詢緩沖區(qū)的大小,可以通過(guò)在Mysql控制臺(tái)觀察,如果Qcache_lowmem_prunes的值非常大,則表明經(jīng)常出現(xiàn)緩沖不夠的情況,如果 Qcache_hits的值非常大,則表明查詢緩沖使用的非常頻繁 :
query_cache_size=64M
query_cache_limit=64M
#設(shè)置內(nèi)在臨時(shí)表最大值,如果超過(guò)該值,則會(huì)將臨時(shí)表寫(xiě)入磁盤(pán),其范圍為1KB至4GB:
tmp_table_size=64M
#指定一個(gè)請(qǐng)求的最大連接時(shí)間,對(duì)于4GB左右內(nèi)在的服務(wù)器來(lái)說(shuō),可以將其設(shè)置為5-10:
wait_timeout=20
#開(kāi)啟該選項(xiàng)可以徹底關(guān)閉MYSQL的TCP/IP連接方式,如果WEB服務(wù)器是以遠(yuǎn)程連接的方式訪問(wèn)MYSQL的數(shù)據(jù)庫(kù)服務(wù)器,則不要開(kāi)啟該選項(xiàng),否則>將無(wú)法正常連接。 skip-networking   抱怨Innodb比MyISAM慢 100倍?那么你大概是忘了調(diào)整這個(gè)值。默認(rèn)值1的意思是每一次事務(wù)提交或事務(wù)外的指令都需要把日志寫(xiě)入(flush) 硬盤(pán),這是很費(fèi)時(shí)的。特別是使用電池供電緩存(Battery backed up cache)時(shí)。設(shè)成2對(duì)于很多運(yùn)用,特別是從MyISAM表轉(zhuǎn)過(guò)來(lái)的是可以的>,它的意思是不寫(xiě)入硬盤(pán)而是寫(xiě)入系統(tǒng)緩存。日志仍然會(huì)每秒flush到硬 盤(pán),所以你一般不會(huì)丟失超過(guò)1-2秒的更新。設(shè)成0會(huì)更快一點(diǎn),但安>全方面比較差,即使MySQL掛了也可能會(huì)丟失事務(wù)的數(shù)據(jù)。而值2只會(huì)在整個(gè)操作系#統(tǒng) 掛了時(shí)才可能丟數(shù)據(jù):
innodb_flush_log_at_trx_commit=2
#這是 InnoDB 存儲(chǔ)引擎的事務(wù)日志所使用的緩沖區(qū)。類似于 Binlog Buffer,InnoDB 在寫(xiě)事務(wù)日志的時(shí)候,為了提高性能,也是先將信息寫(xiě)>入 Innofb Log Buffer 中,當(dāng)滿足 innodb_flush_log_trx_commit 參數(shù)所設(shè)置的相應(yīng)條件(或者日志緩沖區(qū)寫(xiě)滿)之后,才會(huì)將日志寫(xiě)到文>件(或者同步到磁盤(pán))中??梢酝ㄟ^(guò) innodb_log_buffer_size 參數(shù)設(shè)置其可以使用的最大內(nèi)存空間:
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 的默認(rèn)大小是 32M。如果一張臨時(shí)表超出該大小,MySQL產(chǎn)生一個(gè) The table tbl_name is full 形式的錯(cuò)誤,如果你做很多 #高級(jí) GROUP BY 查詢,增加 tmp_table_size 值:
tmp_table_size=512M
#隨機(jī)讀取數(shù)據(jù)緩沖區(qū)使用內(nèi)存(read_rnd_buffer_size):和順序讀取相對(duì)應(yīng),當(dāng) MySQL 進(jìn)行非順序讀取(隨機(jī)讀?。?shù)據(jù)塊的時(shí)候,會(huì)利用>這個(gè)緩沖區(qū)暫存讀取的數(shù)據(jù)。如根據(jù)索引信息讀取表數(shù)據(jù),根據(jù)排序后的結(jié)果集與表進(jìn)行Join等等。總的來(lái)說(shuō),就是當(dāng)數(shù)據(jù)塊的讀取需要滿足>一定的順序的情況下,MySQL 就需要產(chǎn)生隨機(jī)讀取,進(jìn)而使用到 read_rnd_buffer_size 參數(shù)所設(shè)置的內(nèi)存緩沖區(qū):
read_rnd_buffer_size=128M
#默認(rèn)配置沒(méi)開(kāi)查詢緩存:
explicit_defaults_for_timestamp
#需要記錄進(jìn)制日志的數(shù)據(jù)庫(kù).如果有多個(gè)數(shù)據(jù)庫(kù)可用逗號(hào)分隔,或者使用多個(gè)binlog-do-db選項(xiàng):
binlog-do-db=dbname
#不需要記錄進(jìn)制日志的數(shù)據(jù)庫(kù).如果有多個(gè)數(shù)據(jù)庫(kù)可用逗號(hào)分隔,或者使用多個(gè)binlog-do-db選項(xiàng)  :
binlog-ignore-db=dbname
#過(guò)濾掉一些沒(méi)什么大問(wèn)題的錯(cuò)誤:
slave-skip-errors=all
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
host=localhost
user=mysqlback
password='password'

看完了這篇文章,相信你對(duì)“nginx + mysql怎么配置服務(wù)端”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

本文題目:nginx+mysql怎么配置服務(wù)端
轉(zhuǎn)載注明:http://bm7419.com/article44/pscghe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、企業(yè)建站、用戶體驗(yàn)響應(yīng)式網(wǎng)站、軟件開(kāi)發(fā)微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)