如何本地安装nginx及部署项目
作者:luvJie-7c
这篇文章主要介绍了如何本地安装nginx及部署项目问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
1、下载
nginx官网地址:https://nginx.org/en/download.html
选择遗留的稳定版本:

解压到任意位置

2、启动
cmd 进入nginx文件夹 输入命令行:start nginx

打开浏览器,输入: http://localhost:80 出现以下页面即为启动成功

3、部署项目
将项目放到nginx的html文件夹下

4、修改nginx的conf文件夹下的nginx.conf配置文件
配置说明:
- 1、listen:端口号
- 2、server_name:虚拟ip地址
- 3、root:声明默认网站根目录位置 --项目的根目录
- 4、index:定义首页索引文件的名称 --index.html
- 5、try_files:$uri $uri/ /app/index.html; 这里的设置是通过内部重定向的方式,去匹配目录下的索引文件index.html
- 6、location:控制服务访问路径
- 7、proxy_pass:请求代理转发
server {
listen 8011;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.html;
#root html;
#index index.html index.htm;
}
#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;
#}
}
5、重启nginx
cmd 进入nginx文件夹 输入命令行:nginx -s reload

6、效果

7、nginx在windows下的常用命令
启动:
直接点击nginx目录下的nginx.exe 或者
start nginx
关闭:
nginx -s stop
修改配置后重新加载生效并重启nginx:
nginx -s reload
重新打开日志文件:
nginx -s reopen
测试nginx配置文件nginx.conf是否正确:
nginx -t -c /xxx/xx/nginx.conf
8、nginx实现同个ip、端口访问不同的项目(以路径区分项目)
nginx实现同个ip、端口访问不同的项目(以路径区分项目)
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
