標籤:centos7.0 nginx apache
cd /usr/local/srcwget http://nginx.org/download/nginx-1.7.6.tar.gztar –xvf nginx-1.7.6.tar.gzcd nginx-1.7.6./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcremake make installvi /usr/local/nginx/conf/nginx.conf 1user nobody nobody; 2#啟動進程 3worker_processes 5; 4#全域錯誤記錄檔及PID檔案 5error_log logs/error.log notice; 6pid logs/nginx.pid; 7#工作模式及串連數上限 8events { 9#工作模式有:select(標準模式),poll(標準模式),kqueue(高效模式,適用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),10#epoll(高效模式,本例用的。適用Linux 2.6+,SuSE 8.2,), #/dev/poll(高效模式,適用Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+)11use epoll;12worker_connections 1024;13}14#設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援15http {16#設定mime類型17include conf/mime.types;18default_type application/octet-stream;19#設定日誌格式20log_format main ‘$remote_addr - $remote_user [$time_local] ‘21 ‘"$request" $status $bytes_sent ‘22 ‘"$http_referer" "$http_user_agent" ‘23 ‘"$gzip_ratio"‘;2425log_format download ‘$remote_addr - $remote_user [$time_local] ‘ ‘"$request" $status $bytes_sent ‘ ‘"$http_referer" "$http_user_agent" ‘ ‘"$http_range" "$sent_http_content_range"‘;26#設定請求緩衝27client_header_buffer_size 10k;28large_client_header_buffers 4 4k;2930#開啟gzip模組,要求安裝gzip 在運行./config時要指定31gzip on;32gzip_min_length 1100;33gzip_buffers 4 8k;34gzip_types text/plain;35output_buffers 1 32k;36postpone_output 1460;37#設定訪問日誌38access_log logs/access.log main;39client_header_timeout 3m;40client_body_timeout 3m;41send_timeout 3m;42sendfile on;43tcp_nopush on;44tcp_nodelay on;45keepalive_timeout 65;4647#設定負載平衡的伺服器列表48upstream backserver {49#weigth參數表示權值,權值越高被分配到的幾率越大50#本例是指在同一台伺服器,多台伺服器改變ip即可51server 127.0.0.1:8081 weight=5;52server 127.0.0.1:8082;53server 127.0.0.1:8083;54} #Deny access to any host other than (www).4535.com server { server_name _; #default return 404; } 55#設定虛擬機器主機,預設為監聽80連接埠,改成其他連接埠會出現問題56server {57listen 80;58server_name test.com www.test.com;59charset utf8;60#設定本虛擬機器主機的訪問日誌61access_log logs/test.com.log main;62#如果訪問 /images/*, /js/*, /css/* 資源,則直接取本地檔案,不用轉寄。但如果檔案較多效果不是太好。63location ~ ^/(images|js|css)/ {64root /usr/local/testweb;65expires 30m;66}67#對 "/" 啟用負載平衡68location / {69proxy_pass http://backserver;70proxy_redirect off;71proxy_set_header Host $host;72proxy_set_header X-Real-IP $remote_addr;73proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;74client_max_body_size 10m;75client_body_buffer_size 128k;76proxy_connect_timeout 90;77proxy_send_timeout 90;78proxy_read_timeout 90;79proxy_buffer_size 4k;80proxy_buffers 4 32k;81proxy_busy_buffers_size 64k;82proxy_temp_file_write_size 64k;}83#設定查看Nginx狀態的地址,在運行./config 要指定,預設是不安裝的。84location /NginxStatus {85stub_status on;86access_log on;87auth_basic "NginxStatus";88#是否要通過使用者名稱和密碼訪問,測試時可以不加上。conf/htpasswd 檔案的內容用 apache 提供的 htpasswd 工具來產生即可#auth_basic_user_file conf/htpasswd;89}90}91
apache 裡連接埠改成8080
本文出自 “王升的遊泳池” 部落格,請務必保留此出處http://wangsheng1.blog.51cto.com/29473/1563235
centos7 nginx前端 apache後端 及多網站簡單配置