CentOS 7 安装 Nginx+Apache+PHP+Mariadb

16-08-25 12:26 23675 0 未分类

安装epel源

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

for RHEL only

subscription-manager repos –enable=rhel-7-server-optional-rpms

yum --enablerepo=epel,remi install php70-php php-mysql php-mbstring php-gd php-xml
yum --enablerepo=epel,remi install nginx
yum --enablerepo=epel,remi install mariadb-server

yum –enablerepo=epel,remi install postgresql-libs unixODBC

wget http://sphinxsearch.com/files/sphinx-2.2.10-1.rhel7.x86_64.rpm

rpm -ivh sphinx-2.2.10-1.rhel7.x86_64.rpm

systemctl start searchd

systemctl start mariadb /usr/bin/mysql_secure_installation

设置开机自启动

systemctl enable nginx systemctl enable httpd systemctl enable mariadb systemctl enable searchd

启用gzip压缩

httpd.conf修改

Listen 80
↓改成
Listen 127.0.0.1:8888
# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

改为

# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>
location / {
    root   /var/www/html;#apache的网站根目录
    index  index.php index.html index.htm;
}

#将php文件请求分发给后端的apache
location ~ \.php$ { 
    proxy_set_header Host $host;  # 向后端服务器发起请求时添加指定的header头信息
    proxy_set_header X-Real-IP $remote_addr;   # 向后端服务器发送真实 IP
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 让后端如php能直接通过变量获取真实IP
    proxy_pass http://127.0.0.1:8080;
}

# nginx找不到文件时,转发请求给后端Apache
location @proxy {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8080;
}

#将图像和静态文件由nginx处理
location ~ \.*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
    expires 30d;
}

#将js文件由nginx处理 
location ~ \.*.(js|css)$ {
    expires 1h;
}

安装mod_remoteip模块

1、Apache-2.2下配置mod_remoteip如下: 1)、安装 代码如下:

wget https://github.com/ttkzw/mod_remoteip-httpd22/raw/master/mod_remoteip.c
/usr/local/apache/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c

禁止apache目录访问 打开httpd.conf 查找Options Indexes FollowSymLinks 修改为: Options FollowSymLinks 修改保存退出,重新启动apache

2)、修改配置文件: 代码如下:

v httpd.conf
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1

3)、测试: 代码如下:

# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl restart
请登录后发表评论 点击登录

文章归档

文章日历

2024 年 04 月
29 01 02 03 04 05 06
07 08 09 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
29 30 01 02 03 04 05

文章标签

最新评论

友情链接