1. Create a front-end project directory
The /var folder is displayed
cd /var
Copy the code
Create WWW folder in /var directory
mkdir www
Copy the code
Go to the /var/www directory and create the test folder
cd www Enter the WWW directory
mkdir test
Copy the code
2. Upload the compiled file to the /var/www/test directory
3. Configure the test directory and options under nginx
Go to the /etc/nginx/conf.d/ directory
cd /etc/nginx/conf.d/
Copy the code
Open default.conf and write the configuration for test
server {
listen 80; # nginx listens on port
server_name localhost; Replace localhost with domain name
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/test; #test project path
index index.html index.htm; # default start page
try_files $uri $uri/ /index.html; Spa front-end project routing configuration
}
#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;
#}
}
Copy the code
4. Test the deployment
curl localhost Localhost = localhost
Copy the code
Success is achieved if the RETURNED HTML string does not contain an exception status code
5. Troubleshoot errors
1) The host can be accessed using curl, but the client cannot be accessed
Solution: Check whether the listening port is enabled on the firewall of the host
View the open ports of the current host firewall-cmd --list-ports Open the host port firewall-cmd --add-port=80/ TCP --permanent Disable the firewall- CMD on the host port --remove-port=80/tcp --permanentCopy the code
Note: Restart the firewall after opening or closing the port
firewall-cmd --reload
Copy the code
Nginx error: 403 forbidden
Solution: SELinux may be enabled. Disable SELinux
Check the SELinux status
/usr/sbin/sestatus -v If SELinux status is enabled, the SELinux status is enabled
Copy the code
Temporary shutdown (without rebooting the machine, current Settings can be used to verify that SELinux is enabled causing 403 errors)
setenforce 0 Set SELinux to permissive mode
##setenforce 1 sets SELinux to enforcing mode
Copy the code
Permanently closed, editing SELinux (requires reboot)
vi /etc/selinux/config Change SELINUX=enforcing to SELINUX=disabled
Copy the code