我面临以下情况。出于Web开发的目的,我设法使用VirtualBox设置CentOS 7来宾VM。我已经安装了LAMP堆栈并配置了Apache(vhost,添加了组vboxsf的apache成员,添加了防火墙规则)来访问VirtualBox共享文件夹。
GUEST CentOS 7 VM Guest计算机的配置设置:
Virtual machine hostname: dickwan.dev
Shared Folders:
Name | Read-only | Auto-mount
------------------------------------
dickwan | no | yes
------------------------------------
Networking: NAT (with port forwarding rules)
Port Forwarding Rules:
Name | Protocol | Host IP | Host Port | Guest IP | Guest Port
--------------------------------------------------------------------------------------
HTTP | TCP | . . . | 8080 | . . . | 80
--------------------------------------------------------------------------------------
MariaDB | TCP | . . . | 9306 | . . . | 3306
--------------------------------------------------------------------------------------
SSH | TCP | . . . | 2222 | . . . | 22
现在,在我的主机上,我打开浏览器并导航到(让我们说):
http://dickwan.dev:8080/server-status
我收到消息:
Forbidden
You don't have permission to access /server-status on this server.
我已将问题追溯到SELinux安全上下文类型问题。 当SELinux被禁用时,一切正常(好吧......很好是哼)。
但是我觉得关闭安全功能只是一种不好的做法。我试图更改共享文件夹的上下文,但我无法执行操作
是否有机会通过Apache访问共享文件夹而不停用SELinux?
答案 0 :(得分:2)
由于无法更改VBox共享文件夹的安全上下文,因此可以修改SELinux安全策略以允许Apache使用上下文。它类似于在防火墙中打开端口以将某个端口暴露给应用程序。
首先,确保您的apache用户是拥有共享文件夹的组的一部分,如果不是,您可以使用看起来像这样的命令添加它(系统上的用户/组名称可能不同) ):
var Param = React.createClass({
getInitialState: function() {
return {
isLoading: true,
panelTitle: "",
data: [],
categories: []
}
},
updateState: function() {
var that = this;
var categories = new Set();
rest.getParameters('service').then(function (results) {
for (var i = 0; i < results.data.length; i++) {
categories.add(results.data[i].category);
}
that.setState({
data: results.data,
categories: Array.from(categories)
})
}).catch(function (err) {
console.error('rest.getParameters(): ', err);
that.setState({
isLoading: true,
data: [],
categories: []
})
});
},
componentDidMount: function() {
this.updateState();
},
render: function() {
return (
<Panel className="panel-info" header={<h4 className="panel-title">Service Config</h4>}>
<div>
<table className="table table-striped table-bordered table-hover table-condensed table-responsive">
<thead>
<tr>
<th className="col-lg-2 text-center">AMP Name</th>
<th className="col-lg-2 text-center">Athena Name</th>
<th className="col-lg-2 text-center">Description</th>
<th className="col-lg-1 text-center">Default</th>
<th className="col-lg-1 text-center">Min Value</th>
<th className="col-lg-1 text-center">Max Value</th>
<th className="col-lg-1 text-center">Action</th>
</tr>
</thead>
<tbody>
{this.state.categories.map((category, index) =>
<th colSpan="7" key={index} style={{'textAlign':'left', 'paddingLeft':'5px', 'backgroundColor': '#D3D0CF'}}>{this.state.category}</th>
this.state.data.map((row, i) =>
if (row.category === category) {
<tr key={i}>
<td className="col-lg-2 text-center">{row.name}</td>
<td className="col-lg-2 text-center">{row.alias}</td>
<td className="col-lg-2 text-center">{row.description}</td>
<td className="col-lg-1 text-center">{row.default_value}</td>
<td className="col-lg-1 text-center">{row.min_value}</td>
<td className="col-lg-1 text-center">{row.max_value}</td>
<td className="col-lg-1 text-center">Action</td>
</tr>
}
)
)}
</tbody>
</table>
</div>
</Panel>
);
}
});
然后,您可以使用audit2allow生成新的安全策略来解决您的问题。 Here is a good tutorial
如果您很懒并且只想允许对您的VBox共享文件夹进行Apache读取访问,则可以调整以下usermod -aG vboxsf apache
策略文件并使用附带的命令将其应用于您的系统。
my_httpd_t.te
答案 1 :(得分:1)
我遇到了类似的问题(除了Fedora 20作为主机和客户操作系统)。我做了什么:
sudo mount -t vboxsf shared_folder / media / shared_folder
sudo ln -s / media / shared_folder / / var / www /
sudo chcon -R --reference = / var / www / var / www / shared_folder
这对我有用:)
在我尝试将安全上下文设置为自动挂载的共享文件夹(通过VirtualBox)之前,但没有成功,因此我手动挂载