zlzyp 发表于 2018-10-3 08:13:59

nginx + apache + php + mysql-BSDerの

  前期的一些小工作:
  1)安装zlib
  


[*]# cd zlib-1.2.5
[*]# ./configure --prefix=/usr/local/zlib
[*]# make && make install && make clean
  

  2)安装openssl(我们网站支付需要ssl支持)
  


[*]# cd openssl-1.0.0d
[*]# ./config -fPIC --prefix=/usr/local/openssl/ enable-shared
[*]# make && make install && make clean
  

  3)安装curl(php中curl模块,且需启用ssl 支持)
  


[*]# cd curl-7.21.4
[*]# ./configure --prefix=/usr/local/curl      \
[*]            --enable-optimize             \
[*]            --disable-ipv6                \
[*]            --with-ssl=/usr/local/openssl \
[*]            --with-zlib=/usr/local/zlib/
  

  configure之后,显示
  


[*]curl version:    7.21.4
[*]Host setup:      x86_64-unknown-linux-gnu
[*]Install prefix:/usr/local/curl
[*]Compiler:      gcc
[*]SSL support:   enabled (OpenSSL)
[*]SSH support:   no      (--with-libssh2)
[*]zlib support:    enabled
[*]krb4 support:    no      (--with-krb4*)
[*]GSSAPI support:no      (--with-gssapi)
[*]SPNEGO support:no      (--with-spnego)
[*]TLS-SRP support: no      (--enable-tls-srp)
[*]resolver:      default (--enable-ares / --enable-threaded-resolver)
[*]ipv6 support:    no      (--enable-ipv6)
[*]IDN support:   enabled
[*]Build libcurl:   Shared=yes, Static=yes
[*]Built-in manual: enabled
[*]Verbose errors:enabled (--disable-verbose)
[*]SSPI support:    no      (--enable-sspi)
[*]ca cert bundle:/etc/pki/tls/certs/ca-bundle.crt
[*]ca cert path:    no
[*]LDAP support:    enabled (OpenLDAP)
[*]LDAPS support:   enabled
[*]RTSP support:    enabled
[*]RTMP support:    no      (--with-librtmp)
[*]Protocols:       DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTSP SMTP SMTPS TELNET TFTP
  

  4)安装nginx(处理静态页面)
  


[*]# cd nginx-0.8.54
[*]# groupadd www && useradd www -g www -s /sbin/nologin -d /dev/null -M -c "www"
[*]#./configure--prefix=/usr/local/nginx      \
[*]                --user=www                     \
[*]                --group=www                      \
[*]                --with-http_ssl_module         \
[*]                --with-http_sub_module         \
[*]                --with-http_gzip_static_module   \
[*]                --with-http_stub_status_module   \
[*]                --without-http_fastcgi_module    \
[*]                --without-mail_pop3_module       \
[*]                --without-mail_imap_module       \
[*]                --without-mail_smtp_module       \
[*]                --with-pcre=../pcre-8.12         \
[*]                --with-zlib=../zlib-1.2.5      \
[*]                --with-openssl=../openssl-1.0.0d
[*]# make && make install && make clean
  

  注:pcre,zlib,openssl均为源码解压后的目录,这个在./configure --help的时候,有注释说明
  


[*]./configure --help |egrep '(openssl|pcre|zlib)'
[*]--without-pcre                     disable PCRE library usage
[*]--with-pcre                        force PCRE library usage
[*]--with-pcre=DIR                  set path to PCRE library sources
[*]--with-pcre-opt=OPTIONS            set additional options for PCRE building
[*]--with-zlib=DIR                  set path to zlib library sources
[*]--with-zlib-opt=OPTIONS            set additional options for zlib building
[*]--with-zlib-asm=CPU                use zlib assembler sources optimized
[*]--with-openssl=DIR               set path to OpenSSL library sources
[*]--with-openssl-opt=OPTIONS         set additional options for OpenSSL building
  

  configure 后的提示
  


[*]Configuration summary
[*]+ using PCRE library: ../pcre-8.12
[*]+ using OpenSSL library: ../openssl-1.0.0d
[*]+ md5: using OpenSSL library
[*]+ sha1 library is not used
[*]+ using zlib library: ../zlib-1.2.5
[*]
[*]nginx path prefix: "/usr/local/nginx"
[*]nginx binary file: "/usr/local/nginx/sbin/nginx"
[*]nginx configuration prefix: "/usr/local/nginx/conf"
[*]nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
[*]nginx pid file: "/usr/local/nginx/logs/nginx.pid"
[*]nginx error log file: "/usr/local/nginx/logs/error.log"
[*]nginx http access log file: "/usr/local/nginx/logs/access.log"
[*]nginx http client request body temporary files: "client_body_temp"
[*]nginx http proxy temporary files: "proxy_temp"
[*]nginx http uwsgi temporary files: "uwsgi_temp"
[*]nginx http scgi temporary files: "scgi_temp"
  

  配置nginx.conf
  


[*]user www www;
[*]worker_processes 10;
[*]pid logs/nginx.pid;
[*]worker_rlimit_nofile 65536;
[*]
[*]events {
[*]       use epoll;
[*]       worker_connections 51200;
[*]}
[*]
[*]http {
[*]   include mime.types;
[*]   server_names_hash_bucket_size 256;
[*]   default_type application/octet-stream;
[*]   server_tokens off;
[*]   log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
[*]                     '$status $body_bytes_sent "$http_referer" '
[*]                     '"$http_user_agent" "$http_x_forwarded_for"';
[*]
[*]   sendfile on;
[*]   tcp_nopush on;
[*]   tcp_nodelay on;
[*]
[*]   keepalive_timeout 120;
[*]
[*]   client_header_buffer_size 256k;
[*]   client_body_buffer_size 256k;
[*]   client_max_body_size 50m;
[*]   large_client_header_buffers 4 256k;
[*]
[*]   send_timeout 3m;
[*]   client_header_timeout 3m;
[*]   client_body_timeout 3m;
[*]
[*]   connection_pool_size 256;
[*]   request_pool_size 4k;
[*]   output_buffers 4 32k;
[*]   postpone_output 1460;
[*]
[*]   proxy_buffering on;
[*]   proxy_ignore_client_abort off;
[*]   proxy_intercept_errors    on;
[*]   proxy_next_upstream       error timeout invalid_header;
[*]   proxy_redirect            off;
[*]   proxy_set_header          X-Forwarded-For $remote_addr;
[*]   proxy_connect_timeout   60;
[*]   proxy_send_timeout      60;
[*]   proxy_read_timeout      60;
[*]   proxy_cache_min_uses 3;
[*]   proxy_cache_valid any 10m;
[*]   #proxy_cache_path          /dev/shm/proxy_cache_dir levels=1:2 keys_zone=cache:2048m inactive=1d max_size=50g;
[*]   proxy_temp_path         /dev/shm/proxy_temp_dir;
[*]
[*]   gzip on;
[*]   gzip_http_version 1.0;
[*]   gzip_comp_level 8;
[*]   gzip_types text/plain text/css application/x-javascripttext/xml application/xml;
[*]   gzip_min_length 1000;
[*]   gzip_buffers 4 16k;
[*]   gzip_vary on;
[*]
[*]   include ../upstream/http_upstream.conf;
[*]   include ../vhosts/http-vhosts.conf;
[*]   error_log logs/error.log crit;
[*]   access_log logs/access.log combined;
[*]}
  

  http-vhosts.conf
  


[*]server {
[*]       listen 80 default;
[*]       server_name xxx.xxx.xxx.xxx;
[*]       index index.html index.htm index.php;
[*]       root /usr/local/apache/htdocs/public_html;
[*]       include /usr/local/nginx/newurlrewrite.conf;
[*]
[*]       open_file_cache max=200 inactive=2h;
[*]       open_file_cache_valid 3h;
[*]       open_file_cache_errors off;
[*]       #location / {
[*]                #proxy_next_upstream http_502 http_504 error timeout invalid_header;
[*]                #proxy_cache cache;
[*]                #proxy_cache_valid200 304 12h;
[*]                #proxy_cache_valid any 1m;
[*]                #proxy_cache_key $host$uri$is_args$args;
[*]                #proxy_set_header Host $host;
[*]                #proxy_set_header X-Forwarded-For $remote_addr;
[*]                #proxy_pass http://test;
[*]                #add_header Nginx-Cache "$upstream_cache_status from xxx.xxx.xxx.xxxx";
[*]                #expires    1d;
[*]       #}
[*]
[*]       location ~ \.php$ {
[*]                  proxy_set_header   Host             $host;
[*]                  #proxy_set_header   X-Real-IP      $remote_addr;
[*]                  proxy_set_header   X-Forwarded-For$proxy_add_x_forwarded_for;
[*]                  #proxy_redirect   default;
[*]                  proxy_pass http://test;
[*]       }
  

  http_upstream.conf(所有php请求转向apache)
  


[*]upstream test {
[*]         server 192.168.0.112:8080;
[*]         #server 10.36.138.8:10001 fail_timeout=3s weight=1;
[*]}
  

  配置nginx自启动,nginx编译安装后的脚本见本博客其他文章
  5)安装apache(处理动态页面请求)
  


[*]# cd httpd
[*]# ./configure --prefix=/usr/local/apache      \
[*]            --enable-ssl                  \
[*]            --with-ssl=/usr/local/openssl/\
[*]            --enable-rewrite                \
[*]            --with-zlib=/usr/local/zlib/    \
[*]            --enable-mods-shared=rewrite    \
[*]            –-enable-headers                \
[*]            -–enable-deflate                \
[*]            --enable-expires
[*]# make && make install && make clean
  

  配置apache,主配置文件修改(主要配置,小的不说了)
  


[*]对php的处理
[*]  DirectoryIndex index.html index.php
  
[*]AddType application/x-httpd-php .php  AddType application/x-httpd-php-source .phps
[*]
[*]# Real-time info on requests and configuration
[*]Include conf/extra/httpd-info.conf
[*]
[*]# Virtual hosts
[*]Include conf/extra/httpd-vhosts.conf
[*]
[*]# Various default settings
[*]Include conf/extra/httpd-default.conf
[*]
[*]# Server-pool management (MPM specific)  Include conf/extra/httpd-mpm.conf
  

  httpd.conf里面加入
  


[*]# -----------------------------
[*]# add by Henry He on 2011/03/30
[*]# -----------------------------
[*]
[*]# for gzip
[*]
[*]DeflateCompressionLevel 9
[*]AddOutputFilterByType   DEFLATE text/plain application/x-httpd-php
[*]AddOutputFilter         DEFLATEphpcssjs
[*]
[*]
[*]# for expire
[*]#
[*]#ExpiresActive on
[*]#ExpiresDefault "access plus 14 month"
[*]#ExpiresByType text/html "access plus 14 months"
[*]#ExpiresByType text/css "access plus 14 months"
[*]#ExpiresByType image/gif "access plus 14 months"
[*]#ExpiresByType image/jpeg "access plus 14 months"
[*]#ExpiresByType image/jpg "access plus 14 months"
[*]#ExpiresByType image/png "access plus 14 months"
[*]#EXpiresByType application/x-javascript "access plus 14 months"
[*]#
[*]# --------------------- end --------------------------------------
  

  httpd-vhosts.conf
  


[*]NameVirtualHost 192.168.0.112:8080
[*]
[*]#
[*]# VirtualHost example:
[*]# Almost any Apache directive may go into a VirtualHost container.
[*]# The first VirtualHost section is used for all requests that do not
[*]# match a ServerName or ServerAlias in anyblock.
[*]#
[*]
[*]    ServerAdminhenry@abc.com
[*]    DocumentRoot "/usr/local/apache/htdocs/public_html"
[*]    ServerName 192.168.0.112
[*]
  

  httpd-defaults.conf
  


[*]Timeout 120
[*]KeepAlive On
[*]MaxKeepAliveRequests 0
[*]KeepAliveTimeout 3
[*]UseCanonicalName Off
[*]AccessFileName .htaccess
[*]ServerTokens Prod
[*]ServerSignature Off
[*]HostnameLookups Off
  

  httpd-mpm.conf
  


[*]
[*]    ServerLimit         4000
[*]    StartServers          15
[*]    MinSpareServers       15
[*]    MaxSpareServers       30
[*]    MaxClients         4000
[*]    MaxRequestsPerChild   4000
[*]
  

  

  6)php的安装
  


[*]# cd php
[*]# ./configure --prefix=/usr/local/php                  \
[*]            --with-curl=/usr/local/curl                \
[*]            --with-openssl=/usr/local/openssl          \
[*]            --with-apxs2=/usr/local/apache/bin/apxs    \
[*]            --with-mcrypt                              \
[*]            --disable-ipv6                           \
[*]            --with-mhash                               \
[*]            --with-zlib=/usr/local/zlib/               \
[*]            --with-mysql=/opt/mysql/                   \
[*]            --with-mysqli=/opt/mysql/bin/mysql_config\
[*]            --enable-inline-optimization               \
[*]            --disable-debug
[*]# make && make install && make clean
  

  我们的这个php还好不需要gd的支持,否则麻烦死了
  配置php
  


[*]# cp php.ini-production /usr/local/php/lib/php.ini
  

  接着,安装php的扩展memcache,xcache,suhosin等(本博客其他文章)
  编译php.ini,修改以下的参数
  


[*]session.save_handler = memcache
[*]session.save_path = "tcp://192.168.0.10:11211"
[*]
[*]  suhosin.get.max_value_length = 5120


页: [1]
查看完整版本: nginx + apache + php + mysql-BSDerの