设为首页 收藏本站
查看: 402|回复: 0

[经验分享] nginx + apache + php + mysql-BSDerの

[复制链接]

尚未签到

发表于 2018-10-3 08:13:59 | 显示全部楼层 |阅读模式
  前期的一些小工作:
  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_format  main  '$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-javascript  text/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_valid  200 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         DEFLATE  php  css  js


  • # 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 any  block.
  • #

  •     ServerAdmin  henry@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]  suhosin.get.max_value_length = 5120



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-608026-1-1.html 上篇帖子: 开启MySQL log 下篇帖子: centos7.2 安装mysql5.7.13
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表