原文出处 https://www.cnblogs.com/benpao1314/p/13862897.html
一 nginx 下载安装
点击后就会下载,下载完成后开始安装
二 安装
解压
1、下载完成后,解压缩,运行cmd,使用命令进行操作,不要直接双击nginx.exe,不要直接双击nginx.exe,不要直接双击nginx.exe
一定要在dos窗口启动,不要直接双击nginx.exe,这样会导致修改配置后重启、停止nginx无效,需要手动关闭任务管理器内的所有nginx进程,再启动才可以
有时候手动关还关不掉,直接在cmd命令执行
taskkill /fi "imagename eq nginx.EXE" /f
2、使用命令到达nginx的加压缩后的目录
cd E:\installtion\server\nginx-1.18.0
3、启动nginx服务,启动时会一闪而过是正常的
start nginx
4、查看任务进程是否存在,dos或打开任务管理器都行
tasklist /fi "imagename eq nginx.exe"
如果还是什么都没有的话
如果都没有可能是启动报错了查看一下日志,在nginx目录中的logs文件夹下error.log是日志文件
常见的错误:
(1)端口号被占用
(2)nginx文件夹路径含中文
其他错误就详细看log中的描述
关闭nginx服务使用以下命令,同样也是一闪而过是正常的,看一下是否进程已消失即可
快速停止
nginx -s stop
完整有序的关闭
nginx -s quit
三部署
我使用的是vue项目,通过npm run build在根目录下生成dist文件,把dist下的内容放置到E:\installtion\server\nginx-1.18.0\html文件目录下。
对E:\installtion\server\nginx-1.18.0\conf\nginx.conf进行修改配置
server {
listen 8087;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root E:\document\project\hrsc\pm-frontend\dist;
#直接指向打包的目录或者将打包的内容放在nginx的html下都行
#root html;
index index.html index.htm;
}
location /pm/ {
#指向后端的ip 所有pm的接口请求转接到后台
proxy_pass http://localhost:8082;
client_max_body_size 10m;
}
#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 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;
#}
}
修改完要进行reload,如果你nginx已经start后的话就reload就行了
nginx -s reload
访问网址