windows 部署 nginx

windows 部署 nginx

 

一. nginx 安装部署启动

1. 下载 nginx   http://nginx.org/en/download.html

选择稳定版

 

 

下载解压后

在nginx的配置文件是conf目录下的nginx.conf,默认配置的nginx监听的端口为80,如果本地电脑的80端口有被占用,如果本地80端口已经被使用则修改成其他端口。

 

 

 查看80端口是否被占用的命令是

netstat -ano | findstr 0.0.0.0:80 
或 
netstat -ano | findstr "80"

 

 

 启动Nginx

①:直接双击Nginxm目录下的nginx.exe,双击后一个黑色的弹窗一闪而过就消失了,启动就完成了。

②:打开电脑的cmd命令窗口,然后切换到nginx目录下,输入命令 ,回车即可完成启动。 
nginx.exe 
或者
start nginx

 

 

关闭Nginx

①:在cmd命令窗口里面输入nginx命令(快速停止nginx) :

nginx -s stop

 

或者使用(完整有序的停止nginx)命令:

nginx -s quit

 

②:使用taskkill命令:

taskkill /f /t /im nginx.exe

 

 重新加载 nginx 

nginx -s reload

 

 

 

 

访问地址:http://localhost/ 或 http://127.0.0.1

 

 

二. nginx 可视化 nginxWebUI

准备jdk环境:这里使用的 JDK11 

下载:https://blog.csdn.net/weixin_53185848/article/details/111827608

环境变量配置 :https://blog.csdn.net/weixin_43374578/article/details/120245755

 

下载: nginxWebUI :  http://www.nginxwebui.cn/ 

新建安装目录文件夹nginxWebUI(用于存放数据和日志)

 

 

 

 启动nginxWebUI.jar

cmd 进入目录 : E:\tools\nginx

执行命令:

E:\software\nginx>java -jar -Dfile.encoding=UTF-8 E:/software/nginx/nginxWebUI-3.4.0.jar --server.port=8080 --project.home=E:/software/nginx/nginxWebUI/

 

 

 

 

打开地址:http://localhost:8080/adminPage/login

 

 

 

三. nginx 配置

vsCode 打开 Nginx 配置文件,目录:E:\software\nginx\nginx-1.22.0\conf\nginx.conf

 

1. 增加反向代理,当用户访问 http://cdeserver.railplus.com时,跳转到 http://localhost:8092

在http节中增加

    server {
        listen       80;
        server_name  cdeserver.railplus.com;
        
        location / {
            proxy_pass  http://localhost:8092;
        }
    }

 

 2. 发布静态网站(指定地址)

#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  localhost;

location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name cdeserver.railplus.com; location / { proxy_pass http://localhost:8092; } } server { listen 8055; server_name localhost; location / { root D:\IISPublish\stand; index index.html index.htm; } } }

 

 发布vue的history模式,配置如下

    server {
        listen       8055;
        server_name  localhost;
 
        location / {
            root   D:\IISPublish\stand;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        } 
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

 

引用:http://t.zoukankan.com/liuyangfirst-p-13438745.html

 

引用:http://events.jianshu.io/p/8617e7679db4

引用: https://github.com/digitalocean/nginxconfig.io

 

posted @ 2022-09-16 15:04  无心々菜  阅读(925)  评论(0编辑  收藏  举报