1. Create a front-end project directory
Into the / var folder
cd /var
Create a www folder in the / var directory
mkdir www
Into the / var / www directory, create a test folder
cd www #进入www目录
mkdir test
2. Upload the file to the front-end compiler / var / www / test directory
3. nginx test directory and configuration options
Enter /etc/nginx/conf.d/ directory
cd /etc/nginx/conf.d/
Open the configuration default.conf, the written test
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;
#}
}
4. Test the deployment
curl localhost #假设项目端口为80则为localhost
Should the html string returned no abnormal error status code was successful
5. Error Troubleshooting
1) Using curl inside hosts can access the client machine can not access
Solution: Check whether the host firewall listening port is currently open
查看当前主机开放的端口
firewall-cmd --list-ports
开放主机端口
firewall-cmd --add-port=80/tcp --permanent
关闭主机端口
firewall-cmd --remove-port=80/tcp --permanent
Note: Open or closed executing the need to restart the firewall port
firewall-cmd --reload
2) internal and external hosts can not access the page, but can access nginx tips 403 forbidden error page
Solution: SELinux may be open for the state, you can turn off SELinux
View SELinux status
/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
Temporary closure (not reboot can be used to verify that the current setting is turned on to cause 403 errors SELinux)
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
Permanently closed, editing SELinux (need to restart)
vi /etc/selinux/config # 将SELINUX=enforcing 改为 SELINUX=disabled