我有一个URL https:// facebook。****。in,设置为指向目录/ var / www / html / facebook_app。为此的虚拟主机文件是/etc/apache2/sites-available/facebook.****.in.conf。
我想在URL上添加一个指向另一个自定义目录的路径,这样,
https://facebook.****.in/apis -> /var/www/html/apis
我搜索了这个论坛,并在这里找到了一些解决方案
但是我不确定应该在哪里添加别名?应该是default.conf吗?或facebook。****。in.conf文件。
如果它是facebook。****。in.conf文件,我应该如何指定别名?我想将其托管在443端口的SSL上。
facebook。****。in.conf文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName facebook.****.in
ServerAlias facebook.****.in
DocumentRoot /var/www/html/facebook_app/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName facebook.****.in
ServerAlias facebook.****.in
DocumentRoot /var/www/html/facebook_app/
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/apache2/ssl/facebook_****_in.crt
SSLCertificateKeyFile /etc/apache2/ssl/facebook.****.in.key
SSLCertificateChainFile /etc/apache2/ssl/facebook.****.in.ca-bundle
</VirtualHost>
这是.htaccess文件。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
我有一个index.php文件,它将url参数映射到类和方法。
您必须在配置文件的两个部分中都添加ApacheAlias
和Directory
伪指令VirtualHost
,facebook.****.in.conf
以便同时为HTTP和HTTPS连接启用它。
您应该添加的配置代码段必须类似于
Alias "/apis" "/var/www/html/apis"
# Now set directory permission
<Directory "/var/www/html/apis">
AllowOverride None
Options -Indexes +FollowSymLinks
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
</Directory>
我认为您的Apache Server版本高于2.3,因此仅添加Require all granted
语句就可以了,而无需检查版本。我添加它只是为了以防万一。
另外,出于安全性和性能的目的,我还包括了其他一些指令。请在下面找到它们的快速概述
AllowOverride None
:.htaccess
出于安全和性能目的,它禁止使用文件进入目录。Apache Software Foundation建议在http://httpd.apache.org/docs/current/mod/core.html#allowoverride上使用此配置设置“出于安全和性能的原因,请不要在块中将AllowOverride设置为None以外的任何内容。相反,请找到(或创建)引用您实际打算放置.htaccess文件的目录的块。”
Options -Indexes +FollowSymLinks
:该-Indexes
选项将阻止Web服务器(mod_autoindex
具体来说是模块)在所需的URL映射到没有目录的目录DirectoryIndex
(例如index.html文件)时返回目录的格式化列表。除此之外,该+FollowSymLinks
选项还允许服务器遵循该目录中的符号链接。您可以Options
在http://httpd.apache.org/docs/current/mod/core.html#options的Apache Web Server官方文档中获取有关该语句和其他可用选项的更多信息。还请记住为/var/www/html/apis
运行Apache服务器的用户(www-data
默认情况下在Ubuntu中)对目录和文件设置正确的权限,并重新启动Apache服务以使更改生效。
sudo service apache2 restart
更新
如果该目录中没有文件(例如index.php),也可以将DirectoryIndex
指令包括在Directory
块中index.html
DirectoryIndex index.php
也可以指定多个文件。在这种情况下,将返回找到的第一个文件
DirectoryIndex index.html index.php
有关它的更多信息,请访问http://httpd.apache.org/docs/current/es/mod/mod_dir.html#directoryindex
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句