简体   繁体   中英

Nginx configuration setup for windows

I am trying to run my vue applications trough nginx on windows and i was using the following tutorials, one to run nginx with AlwaysUp and the other one to configure it.

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

I also stumbled upon the following stack overflow question which is basically the problem i have but it didnt work:

nginx Windows: setting up sites-available configs

The service is running and recognizes the two domains i am trying to set up but for whatever reason it always sends me back to the NGINX Welcome page and i am not sure what i am doing wrong.

I followed the steps on the second tutorial and did a few changes, such ass adding "server_names_hash_bucket_size 64;" to my nginx.config file. I also created the symlink between the "sites-available" and "sites-enabled directories" using windows mklink.

Here are my files.

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;
        }

        }
    }

My app config file in sites-available which also contains a symlink in sites-enabled:

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";
}

}

I also faced the issue how to kill the nginx process. I stumbled a while until I came up with the following command which works:

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

Well, after many hours i actually found out what was happening. Everything in my files, from the nginx.conf file to every other .conf files were ok.

However i discovered that when restarting or stop/starting my nginx service with either the AlwaysUp program or the windows service options the service would still be active somehow and wouldnt apply my changes, therefore it would always show me the "welcome to nginx" page.

So i just restarted my computer because i wasnt able to kill the service with conventional means and it worked just fine for every single app i have.

I am sure there is a better way to kill the service and restart it but restarting my computer so the changes to my files would actually be applied solved it.

EDIT: I also discovered that windows takes a little while to stop the nginx service, so if you are using always up try stopping the service there, if it fails try stopping the service trough windows services menu. Also don't forget to set it to manual so you wont accidentally access you nginx app instead of your actual deployed app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM