LAMP+LNMP安装注意问题及安装

一、LAMP安装注意事项

  1. 必须先安装apache再安装 php,apache支持php需要生成libphp5.so 文件,需要编译时添加该语句 --with-apxs2=/usr/local/apache/bin/apxs
  2. apache配置文件修改注意事项
    2.1. AllowOverride None  #修改为:AllowOverride All (允许.htaccess)
    2.2.DirectoryIndex index.html #修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)
    2.3.MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增加同时连接数)
    2.4.设置工作目录 #说明: 搜索DocumentRoot, 修改为 DocumentRoot "/var/www/html" 搜索, 修改为 "/var/www/html">
    2.5. 设置默认文档 : 索, 修改为 DirectoryIndex index.html index.php
    2.6.增加php类型 AddType application/x-gzip .gz .tgz在后面添加 AddType application/x-httpd-php .html .php
    2.6.#修改配置文件 vi /etc/httpd/httpd.conf
    #查找ServerName,将注释去掉 ServerName www.example.com:80 www.example.com->需要改的ip
    2.7.#添加到自启动
    echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit #将apache添加到系统服务中
    cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
    vi /etc/rc.d/init.d/httpd
    #在#!/bin/sh后添加下面两行(包含"#")
    # chkconfig:2345 85 15
    # description:Apache
    #添加执行权限 chmod 755 /etc/init.d/httpd
    #添加到系统服务中 chkconfig --add httpd
    #开启apache service httpd start

*注:设置SELinux为permissive模式 命令行下 setenforce 0 立即生效,重启失效 修改配置文件后, 重启apache才能生效

二、LNMP安装
必须开启 --enbale-fpm

groupadd www
useradd -s /sbin/nologin -g www www

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module  

make && make install
   软连接
ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx

修改配置文件支持php
可把 root 改为想要的目录
打开一下 #

#location ~ \.php$ {
#            root           /home/wwwroot/;
#            fastcgi_pass   127.0.0.1:9000;
#            fastcgi_index  index.php;
#            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#            include        fastcgi_params;
#        }

like this:


 location ~ \.php$ {
            root           /home/wwwroot/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

也可以把给段配置改为改
*$document_root指 定义的根目录

location ~\.php{
fastcgi_pass unix:/tmp/php-fcgi.sock; //下面解释
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}

*fastcgi_pass 里的 127.0.0.1:9000; 可改为unix:/tmp/php-fcgi.sock;
需要更改 php-fpm.conf 需要添加
group=www
user=www
listen=/tmp/php-fcgi.sock
listen.owner= www
listen.group =www

还要建立 /tmp/php-fcgi.sock; touch /tmp/php-fcgi.sock

chown www:www /tmp/php-fcgi.sock 赋予其权限

nginx -s reload

php-fpm 重启

配置文件 :


server{

listen 8080;
server_name 192.168.139.134:8080;
index  index.html index.htm index.php;
root   /home/wwwroot/demo;

location ~\.php{

fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;

}

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$
        {
            expires    30d;

        }

        location ~ .*\.(js|css)?$
        {
            expires    12h;
        }

***************************************************

#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;


events {
    worker_connections  1024;
}


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 {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/wwwroot/;
            index  index.html index.htm index.php;
   }

        #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   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           /home/wwwroot/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
 #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

include vhost/*.conf;
}

//nginx 负载均衡 反相代理

upstream redis { //redis自定义的 和下面 proxy_pass http://redis;名称对应
    server 192.168.244.129:8080;
     server 192.168.244.109:8080;
     #ip_hash;//
}
server {
    listen      8787; //主机端口
    server_name 192.168.0.123:8787; 主机端口 ip
    location / {
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://redis;

    }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp4)$
        {
            expires    30d;

        }

        location ~ .*\.(js|css)?$
        {
            expires    12h;
        }

}

你可能感兴趣的:(nginx,apache)