首页 > 解决方案 > Windows 的 Nginx 配置设置

问题描述

我正在尝试通过 Windows 上的 nginx 运行我的 vue 应用程序,并且我正在使用以下教程,一个是使用 AlwaysUp 运行 nginx,另一个是配置它。

https://www.coretechnologies.com/products/AlwaysUp/Apps/RunNginxAsAService.html https://graspingtech.com/nginx-virtual-hosts-ubuntu-16-04/

我还偶然发现了以下堆栈溢出问题,这基本上是我遇到的问题,但它没有用:

nginx Windows:设置站点可用配置

该服务正在运行并识别我尝试设置的两个域,但无论出于何种原因,它总是将我发送回 NGINX 欢迎页面,我不确定我做错了什么。

我按照第二个教程的步骤进行了一些更改,例如添加“server_names_hash_bucket_size 64;” 到我的 nginx.config 文件。我还使用 windows mklink 在“站点可用”和“启用站点的目录”之间创建了符号链接。

这是我的文件。

Nginx.config

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    server_names_hash_bucket_size  64;
    include       mime.types;
    default_type  application/octet-stream;
    include       "C:/nginx/nginx/sites-available/*.conf";
    sendfile        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;
    listen [::]:80;

    server_name myapp.nginx.br;

    root "C:/Users/Documents/git-repository/my-app/dist";

    index index.html;

    location / {
        try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
        rewrite ^(.+)$ /index.html last;
    }


    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

}

标签: windowsvue.jsnginx

解决方案


我还面临如何终止nginx进程的问题。我偶然发现了一段时间,直到我想出了以下有效的命令:

taskkill /F /FI "IMAGENAME eq nginx.exe"

推荐阅读