One of the nginx functions can start a local server and access target files by configuring server_name and root directory, etc.
1. Download
Unzip after download
2. Modify the configuration file
The nginx configuration file is in nginx-1.8.0\conf\nginx.conf
http {
gzip on;
#static files
server {
listen 80;
server_name static.cnblog.com;
location / {
root G:/source/static_cnblog_com;
}
}
#html file
server {
listen 80;
server_name 127.0.0.1 localhost;
location / {
root G:/source/html/mobile/dist;
index index.html index.htm;
}
}
}
As shown in the figure above, multiple servers can be configured, so that accessing localhost will access the G:/source/html/mobile/dist directory, and you can also enable gzip to compress html
3. Start
Be careful not to double-click nginx.exe directly, this will make it invalid to restart and stop nginx after modifying the configuration, you need to manually close all nginx processes in the task manager
In the nginx.exe directory, open the command line tool and use the command to start/shutdown/restart nginx
start nginx : start nginx
nginx -s reload : Reload takes effect after modifying the configuration
nginx -s reopen : reopen the log file
nginx -t -c /path/to/nginx.conf to test whether the nginx configuration file is correct
Shut down nginx:
nginx -s stop : stop nginx quickly
nginx -s quit : stop nginx in a complete and orderly manner
If an error is encountered:
nginx -t -c /path/to/nginx.conf to test whether the nginx configuration file is correct
Shut down nginx:
nginx -s stop : stop nginx quickly
nginx -s quit : stop nginx in a complete and orderly manner
If an error is encountered:
bash: nginx: command not found
It is possible that you have run the windows command in the linux command line environment,
If you allowed nginx -s reload to report errors before, try ./nginx -s reload
Or use the command line tool that comes with the Windows system to run