进入/var文件夹php
cd /var
在/var目录下建立www文件夹html
mkdir www
进入/var/www目录,建立test文件夹前端
cd www #进入www目录 mkdir test
进入/etc/nginx/conf.d/目录linux
cd /etc/nginx/conf.d/
打开default.conf,写入test的相关配置nginx
server { listen 80; # nginx监听端口 server_name localhost; #如有域名则将localhost替换为域名 #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /var/www/test; #test项目路径 index index.html index.htm; #默认起始页 try_files $uri $uri/ /index.html; #spa前端项目路由配置 } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
curl localhost #假设项目端口为80则为localhost
如若返回的html字符串中没有异常报错的状态码则为成功curl
解决方法:检查当前主机防火墙是否开放监听的端口tcp
查看当前主机开放的端口 firewall-cmd --list-ports 开放主机端口 firewall-cmd --add-port=80/tcp --permanent 关闭主机端口 firewall-cmd --remove-port=80/tcp --permanent
注意:执行完开放或者关闭端口后须要重启防火墙测试
firewall-cmd --reload
解决办法:可能为SELinux为开启的状态,关闭SELinux便可url
查看SELinux状态spa
/usr/sbin/sestatus -v ##若是SELinux status参数为enabled即为开启状态
临时关闭(不用重启机器,当前设置可用于验证是否为SELinux开启致使403的错误)
setenforce 0 ##设置SELinux 成为permissive模式 ##setenforce 1 设置SELinux 成为enforcing模式
永久关闭,编辑SELinux(须要重启)
vi /etc/selinux/config # 将SELINUX=enforcing 改成 SELINUX=disabled