安装:
yum -y install httpd mod_php
# 默认目录是:/var/www/html
支持目录索引:
a. 首页索引:
vim /etc/httpd/conf.d/welcome.conf
b. 自定义索引样式:
vim /etc/httpd/conf/httpd.conf
支持php:
a. 安装mod_php:
yum -y install mod_php
b. 修改配置文件:
开启pathinfo:
解决跨域:
开启rewrite功能:
配置虚拟主机:
防盗链:
配置rewrite:
vim /var/www/html/.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
设置索引文件:
DirectoryIndex index.html index.php
设置服务器名:
ServerName dollarphp
使支持react(写.htaccess文件):
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
开启gzip扩展:
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|doc|avi|mov|mp3|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript
白名单设置:
Order Deny,Allow
Allow from 192.168.8.1/24
Deny from All
修改上传文件大小限制:
LimitRequestBody 10485760
配置文件参考:
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
ServerName dollarphp
AllowOverride none
Require all denied
Order Deny,Allow
Allow from 192.168.8.1/24
Deny from All
LimitRequestBody 10485760
DocumentRoot "/var/www/html"
AllowOverride None
Require all granted
Header set Access-Control-Allow-Origin *
Options Indexes FollowSymLinks
IndexStyleSheet "/css/style.css"
IndexOptions FancyIndexing HTMLTable ScanHTMLTitles FoldersFirst NameWidth=85 DescriptionWidth=128 IconWidth=16 IconHeight=16 VersionSort Charset=UTF-8
AllowOverride all
Require all granted
AcceptPathInfo on
DirectoryIndex index.php index.html
Require all denied
ErrorLog "logs/error_log"
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
CustomLog "logs/access_log" combined
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AllowOverride None
Options None
Require all granted
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddType application/x-httpd-php .php .phtml .php3 .inc
AddOutputFilter INCLUDES .shtml
AddDefaultCharset UTF-8
MIMEMagicFile conf/magic
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|doc|avi|mov|mp3|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript
EnableSendfile on
IncludeOptional conf.d/*.conf
ServerName www.dollarphp.com
DocumentRoot "/var/www/html/dollarphp/"
DirectoryIndex index.php index.html
Header set Access-Control-Allow-Origin *
Options FollowSymLinks
AllowOverride All
Require all granted