installation
http://nginx.org/en/download.html
Download and unzip
Directory Structure
- Conf: configuration file
- html: static files
- logs: log files
Common commands
Open a command line window (cmd under the window), enter the installation directory and execute the command
- Graceful exit: nginx -s quit
- Force exit: nginx -s stop
- Restart: nginx -s reopen
- Start: start nginx.exe
Configuration case
Scenario 1: Set up proxy
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
/***这里是配置内容-start***/
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://165.168.0.70:8000;
proxy_redirect default ;
}
/***这里是配置内容-end***/
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Scenario 2: Jump to the homepage if the address is not accessible
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
try_files $uri /index.html; //这里是配置内容
}
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://165.168.0.70:8000;
proxy_redirect default ;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}