centos7.3 直接用yum安装nginx的版本是1.10.2,当前的最新稳定版是1.10.3,暂时不更新,直接安装php
sudo yum install -y nginx
测试html
nginx -t
启动linux
sudo service nginx start ps -ef|grep nginx curl -i localhost
在virtualbox设置网络的端口转发主机8080转发为子系统的80端口,这样就能够在windows下的浏览器中输入http://localhost:8080 查看了。 在virtualbox修改是临时有效,重启时会丢失配置。最好同时修改vagrant配置文件Vagrantfilenginx
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip:"127.0.0.1"
加入开机启动vim
# sudo chkconfig nginx on sudo systemctl enable nginx.service
sudo service php-fpm start
此次启动应该不会报错了windows
具体站点的配置应该在/etc/nginx/conf.d/
目录增长配置文件,咱们配置开发环境直接修改nginx.conf文件centos
cd /etc/nginx sudo vim nginx.conf
有用的配置段浏览器
... #更改nginx的用户身份 user nginx; ... http { ... server { ... #注释掉默认的根目录 # root /usr/share/nginx/html; root /vagrant ... location / { #autoindex on; index index.html index.php; } location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ... } }
wq
保存。 如今你已经能够在windows下你的共享目录编写php代码了。 新建test.php文件以下网络
<?php phpinfo();
而后windows下浏览器访问http://localhost:8080/test.php 好像一切正常。 等一下,创建一个test.html试试看呢?访问http://localhost:8080/test.html, 熟悉的403来袭curl
403 Forbidden 那么是什么问题呢?
#SELinux status: enabled sestatus -v
暂时关闭selinux测试一下
sudo setenforce 0
能够看到test.html的内容了。 那么如何解决这个问题呢?
修改配置文件
sudo vim /etc/selinux/config
# enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled
重启虚拟机,windows cmd下
vagrant halt vagrant up