运行命令:start nginx
关闭所有进程的命令:taskkill /f /t /im nginx.exe
更新进程的命令:nginx -s reload
配置反向代理
找到nginx\conf\nginx.conf
配置代码如下:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# 可以是本地路径打包前端项目的路径
root xxx\web;
index index.html index.htm;
# rewrite index.html permanent;
# 让Vue项目打包的代码,刷新页面不受影响
try_files $uri $uri/ /index.html;
}
location /api {
# rewrite ^/api/(.*)$ /$1 break; #重置api
proxy_pass http://127.0.0.1:8001; #****后端接口地址
}
}
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root C:\Users\qctc\Desktop\学习\mini_product\pc;
# index index.html index.htm;
# rewrite index.html permanent;
# try_files $uri $uri/ /index.html;
#底下是你node监听的地址;
# 是访问服务器上运行的前端项目
proxy_pass http://127.0.0.1:8001;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}