鍩轰簬 Centos 7 鎼缓Nginx锛堝寘鍚櫄鎷熶富鏈猴級
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍩轰簬 Centos 7 鎼缓Nginx锛堝寘鍚櫄鎷熶富鏈猴級相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/dns' title='dns'>dns 骞跺彂 绀句氦缃戠粶 event tar status mat blog web
Nginx涓撲负鎬ц兘浼樺寲鑰屽紑鍙戯紝鍏舵渶澶х殑浼樼偣灏辨槸瀹冪殑绋冲畾鎬у拰浣庣郴缁熻祫婧愭秷鑰楋紝浠ュ強瀵筯ttp骞跺彂杩炴帴鐨勯珮澶勭悊鑳藉姏锛屽崟鍙扮墿鐞嗘湇鍔″櫒鍙敮鎸?0000~50000涓苟鍙戣姹傦紝姝f槸濡傛锛屽ぇ閲忔彁渚涚ぞ浜ょ綉缁溿€佹柊闂昏祫璁€佺數瀛愬晢鍔″強铏氭嫙涓绘満绛夋湇鍔$殑浼佷笟绾风悍閫夋嫨Nginx鏉ユ彁渚泈eb鏈嶅姟锛岀洰鍓嶄腑鍥藉ぇ闄嗕娇鐢╪ginx缃戠珯鐢ㄦ埛鏈夛細鏂版氮銆佺綉鏄撱€佽吘璁?鍙﹀鐭ュ悕鐨勫井缃戝織Plurk涔熶娇鐢╪ginx銆?br/>Apache 鍜?nginx 鐨勫尯鍒細https://blog.51cto.com/14227204/2435423涓嬮潰寮€濮嬪畨瑁?Nginx锛?br/>涓€銆佸噯澶囧伐浣滐細
Centos 7 绯荤粺鍙婂厜鐩?br/>缂栬瘧瀹夎鐨勮蒋浠跺寘锛?https://pan.baidu.com/s/1-GaLSYxt4fP5R2gCVwpILA
鎻愬彇鐮? kph5
涔熷彲浠ヤ粠瀹樼綉 https://nginx.org/ 涓嬭浇浣跨敤
浜屻€佸紑濮嬫惌寤篘ginx缃戠珯锛?/strong>
瀹夎鎵€闇€瑕佺殑渚濊禆鍖呭苟鍗歌浇褰撳墠鏈夌殑 httpd 鏈嶅姟锛堝鏋滅‘瀹氭病鏈夛紝鍙渷鐣ワ級锛?/p>
[root@mysql yum.repos.d]# yum -y erase httpd
[root@mysql /]# yum -y install pcre-devel zlib-devel # 瀹夎鎵€闇€渚濊禆鍖?/code>
缂栬瘧瀹夎鍙婇厤缃紭鍖?Nginx锛?/strong>
[root@mysql /]# useradd -M -s /sbin/nologin nginx # Nginx 榛樿浠?nobody 韬唤杩愯锛屽缓璁垱寤轰竴涓笓闂ㄧ殑鐢ㄦ埛璐﹀彿
[root@mysql /]# tar zxf nginx-1.12.0.tar.gz -C /usr/src/
[root@mysql /]# cd /usr/src/nginx-1.12.0/
[root@mysql nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx > --group=nginx --with-http_stub_status_module && make && make install
[root@mysql /]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ # 鍒涘缓閾炬帴鏂囦欢锛屾柟渚垮懡浠や娇鐢?/code>
Nginx 杩愯鎺у埗锛?/strong> 2銆佸惎鍔ㄣ€佸仠姝?Nginx 娉ㄦ剰锛氭渶灏忓寲瀹夎鐨?centos 7 榛樿娌℃湁瀹夎 killall 鍛戒护锛屽彲浠ヤ娇鐢?鈥測um -y install psmisc鈥?/strong> 浠ヤ笂鐨勪紭鍖栨槸鍩轰簬鍏ㄥ眬閰嶇疆瀹炴柦鐨勶紝鍚勯」浼樺寲鐨勫惈涔夊涓嬶細 1銆亀orker_processes 锛氳〃绀哄伐浣滆繘绋嬬殑鏁伴噺锛岃嫢鏈嶅姟鍣ㄧ敱澶氬潡CPU鎴栬€呬娇鐢ㄥ鏍稿鐞嗗櫒锛屽彲浠ュ弬鑰僀PU鏍稿績鎬绘暟鏉ユ寚瀹氬伐浣滆繘绋嬫暟銆傚叿浣撳惈涔夊湪worker_connections閰嶇疆椤逛腑浣撶幇鍑烘潵锛?br/>2銆亀orker_connections锛氳繖涓厤缃」鎸囧畾鐨勬槸姣忎釜杩涚▼澶勭悊鐨勮繛鎺ワ紝涓€鑸湪10000浠ヤ笅锛堥粯璁や负1024锛夛紝涓庝笂闈㈠伐浣滆繘绋嬫暟閲忕殑閰嶇疆椤瑰叧鑱旓紝涓句釜鏍楀瓙锛氳嫢宸ヤ綔杩涚▼鏁颁负8锛屾瘡涓繘绋嬪鐞?096涓繛鎺ワ紝鍒欏厑璁窷ginx姝e父鎻愪緵鏈嶅姟鐨勮繛鎺ユ暟宸茬粡瓒呰繃浜?涓囦釜锛?096*8=32768锛夈€傚綋鐒讹紝鍏蜂綋杩樿鐪嬫湇鍔″櫒纭欢銆佺綉缁滃甫瀹界瓑鐗╃悊鏉′欢鐨勬€ц兘琛ㄧ幇銆?/p>
鎼缓鍩轰簬鍩熷悕鐨勮櫄鎷?web 涓绘満锛?/strong> 浠ヤ笂閰嶇疆鍙槸鎼缓浜嗕竴涓綉绔欐湇鍔★紝鑻ユ兂杩愯澶氫釜锛屽彲澶嶅埗閰嶇疆鏂囦欢鏈€鍚庨潰鎻愪緵鐨勬ā鏉匡紝绮樿创鍒?鈥渟erver 鈥濋厤缃笂闈紝鍥犱负鍦ㄩ厤缃枃浠朵腑鏈夊お澶氱殑 鈥? 鈥濓紝涓轰簡閬垮厤閿欒锛屾墍浠ユ墠闇€澶嶅埗鍒板師鏈夌殑 鈥渟erver 鈥濅箣涓婏紝濡備笅锛?/strong> 铏氭嫙涓绘満鍒版灏遍厤缃畬鎴愪簡锛岀劧鍚庨噸鍚湇鍔′娇閰嶇疆鐢熸晥锛孌NS 鑷閰嶇疆锛屽彲鍙傝€冨崥鏂囷細https://blog.51cto.com/14227204/2384462 瀹㈡埛鏈哄紑濮嬮獙璇侊細 以上是关于鍩轰簬 Centos 7 鎼缓Nginx锛堝寘鍚櫄鎷熶富鏈猴級的主要内容,如果未能解决你的问题,请参考以下文章 鍒嗗竷寮忎簨鍔′箣濡備綍鍩轰簬RocketMQ鐨勪簨鍔℃秷鎭壒鎬у疄鐜板垎甯冨紡绯荤粺鐨勬渶缁堜竴鑷存€э紵
1銆佹鏌ラ厤缃枃浠?/p>
[root@mysql /]# nginx -t # 妫€鏌ラ厤缃枃浠讹紝濡傛灉鍑虹幇 OK 鎴?successful 瀛楁牱璇存槑娌¢棶棰?nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@mysql /]# nginx # 鍚姩
[root@mysql /]# killall -s HUP nginx # 閲嶅惎 閫夐」 -s HUP 绛夊悓浜? -1
[root@mysql /]# killall -s QUIT nginx # 鍏抽棴 閫夐」 -s QUIT 绛夊悓浜?-3
涓轰簡浣?Nginx 鏈嶅姟鐨勫惎鍔ㄣ€佸仠姝€侀噸杞界瓑鎿嶄綔鏇存柟渚匡紝鍙互缂栧啓涓€涓?Nginx 鏈嶅姟鑴氭湰锛岃繖浜氬瓙鏇寸鍚?Centos 绯荤粺鐨勭鐞嗕範鎯細[root@mysql /]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "USAGE:$0 start | stop | restart | reload"
exit 1
esac
exit 0
[root@mysql /]# chmod +x /etc/init.d/nginx // 鎺堜簣鏉冮檺
[root@mysql /]# chkconfig --add nginx // 娣诲姞涓虹郴缁熸湇鍔?[root@mysql /]# systemctl start nginx // 鍚姩 Nginx
[root@mysql /]# vim /usr/local/nginx/conf/nginx.conf
...................
#user nobody; // 杩愯鐢ㄦ埛
worker_processes 1; // 宸ヤ綔杩涚▼鏁伴噺
#error_log logs/error.log; // 閿欒鏃ュ織鏂囦欢鐨勪綅缃?#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; // PID 鏂囦欢鐨勪綅缃?
events
use epoll; // 浣跨敤 epoll 妯″瀷锛屼互鎻愰珮鎬ц兘
worker_connections 4096; // 姣忎釜杩涚▼澶勭悊 4096 涓繛鎺?
HTTP閰嶇疆锛?br/>Nginx鐨勯厤缃枃浠朵娇鐢ㄢ€渉ttp 鈥濈晫瀹氭爣璁扮敤浜庤瀹欻TTP鏈嶅姟鍣紝鍖呮嫭璁块棶鏃ュ織銆乭ttp绔彛銆佺綉椤电洰褰曘€侀粯璁ゅ瓧绗﹂泦銆佽繛鎺ヤ繚鎸侊紝浠ュ強铏氭嫙web涓绘満銆乸hp瑙f瀽绛夌綉绔欏叏灞€璁剧疆锛屽叾涓ぇ閮ㄥ垎鍖呭惈鍦ㄥ瓙鐣屽畾鏍囪 鈥?server 鈥濆唴銆傗€?server 鈥濅唬琛ㄤ竴涓叿浣撶殑缃戠珯璁剧疆銆?/p>
[root@mysql /]# vim /usr/local/nginx/conf/nginx.conf
................... 鐪佺暐閮ㄥ垎鍐呭
http
include 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"鈥?
access_log logs/access.log main; // 璁块棶鏃ュ織浣嶇疆
sendfile on; // 寮€鍚珮鏁堜紶杈撴枃浠舵ā寮? #tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; // 杩炴帴淇濇寔瓒呮椂
#gzip on;
server // web 鏈嶅姟鐨勭洃鍚厤缃? listen 80; // 鐩戝惉鍦板潃鍙婄鍙? server_name www.test1.com; // 缃戠珯鍚嶇О FQDN
charset koi8-r; // 缃戦〉鐨勯粯璁ゅ瓧绗﹂泦
access_log logs/host.access.log main;
location / // 鏍圭洰褰曢厤缃? root html; // 缃戠珯鏍圭洰褰曠殑浣嶇疆锛岀浉瀵逛簬瀹夎鐩綍
index index.html index.php; // 榛樿棣栭〉锛岀储寮曢〉
error_page 500 502 503 504 /50x.html; // 鍐呴儴閿欒鐨勫弽棣堥〉闈? location = /50x.html // 閿欒椤甸潰閰嶇疆
root html;
[root@mysql /]# vim /usr/local/nginx/conf/nginx.conf
server
listen 80;
server_name www.test1.com;
charset utf-8;
access_log logs/host.access.log main;
location /
root /var/www/test1;
index index.html index.php;
location /status
stub_status on;
access_log off;
server
listen 80;
server_name www.test2.com;
charset utf-8;
access_log logs/host.access.log main;
location /
root /var/www/test2;
index index.html index.php;
[root@mysql /]# nginx -t # 閲嶅惎鏈嶅姟涔嬪墠锛屾渶濂芥槸妫€娴嬩竴涓?nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@mysql /]# systemctl restart nginx
[root@mysql named]# mkdir -p /var/www/test1 # 鍒涘缓缃戠珯鏍圭洰褰?[root@mysql named]# mkdir -p /var/www/test2
[root@mysql named]# echo www.test1.com > /var/www/test1/index.html # 鍒涘缓娴嬭瘯鏂囦欢
[root@mysql named]# echo www.test2.com > /var/www/test2/index.html
鏌ョ湅褰撳墠鐨勭姸鎬佷俊鎭細
娴嬭瘯鍙︿竴涓煙鍚嶏細