Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deploy nginx under windows Server2008

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

In the previous articles, we used nginx in the linux environment, today due to the needs of our work. You also need to use nginx to build a web server in a windows environment.

The following records the construction and configuration under nginx.

Note that the windows server 2003 64bit used in this lab is also in a virtual machine. The IP address is 192.168.1.221

First, go to the official website to download the latest Windows version of nginx, as follows:

Http://nginx.org/en/download.html

After downloading to the package, extract the nginx-1.7.6.zip package to your favorite root directory and change the directory name to nginx.

Then at the command line, switch the home directory of nginx to do the following:

Cd nginx

Start nginx

Thus, the nginx service starts. Open the task manager, look at the nginx.exe process, there are two processes will show that the use of system resources, which is quite small. As shown below:

Then open the browser, type http://127.0.0.1, and you can see the welcome page of nginx. As follows:

In fact, we can also do the following operations on nginx on the command line:

Nginx-h / / View nginx's help

Nginx-s stop / / stop nginx

Nginx-s reload / / reload the configuration file

The next step is to configure nginx's conf file. The nginx configuration file under Windows is the same as the linux configuration file. Here is my configuration:

Worker_processes 1

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

Keepalive_timeout 65

Server {

Listen 80

Server_name localhost

Access_log logs/host.access.log main

Location / {

Root E:\ MikroTikRouterOS

Autoindex on

}

}

Now let's take a look at the nginx startup after I have configured it. As follows:

From the figure above, we can clearly see that nginx can still start normally after configuration. I have this configuration to use nginx as a http file server.

In theory, after the above configuration is completed, we can use it normally. But the nginx under windows is different from the nginx under linux. The nginx under linux can be started with the system startup, while the one under windows is different.

But in order to enable nginx to start when the windows system starts, we can do it through the software "Windows Service Wrapper". But before we can do that, there are a few things we need to do:

First of all, the windows system must install the .NET program. This is to support Windows Service Wrapper software. As follows:

Let's formally configure Windows Service Wrapper:

1. Then download the latest version of the Windows Service Wrapper program, for example, the name I downloaded is "winsw-1.9-bin.exe", and then name it as you want, such as "winsw.exe". Of course, you don't have to change it.

2. Copy the renamed winsw.exe file to the home directory of nginx. Here is "E:\ nginx".

3. Then create a XML configuration file for Windows Service Wrapper under the nginx home directory, and the name must be the same as the name winsw.exe used in the first step of renaming, for example, "winsw.xml" in my case. As follows:

The winsw.xml file is as follows:

Nginx

Nginx

Nginx

E:\ nginx\ nginx.exe

E:\ nginx\

Roll

-p E:\ nginx\

-p E:\ nginx\-s stop

Execute the following command from the command line to install nginx as a Windows service. As follows:

Winsw.exe install

From the figure above, we can clearly see that nginx has been successfully installed into the service of the system.

Next, we just need to restart the server. Now test it:

It is obvious that our requirements have been fully met this time.

Add:

The command format for Windows Servcie Wrapper is as follows:

# installation Services

CMD:\ > winsw.exe install

# Uninstall the service

CMD:\ > winsw.exe uninstall

# start the service

CMD:\ > winsw.exe start

# stop the service

CMD:\ > winsw.exe stop

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report