Configuration in CentOS / Windows Nginx (and step on pit)

Configuration in CentOS / Windows Nginx (and step on pit)

1. Introduction

Because more of these articles online, the actual operation is also very much the same, so I will not focus on detailed configuration, but will write when I stepped configuration pit.


2. CentOS

2.1 The first step download package nginx

I chose the bag on / usr / local under

cd /usr/local

wget (nginx download directory URL)

Here you can download directory to determine selection according to the version please click nginx download View catalog


2.2 environment required to install nginx

yum install gcc-c++

yum install pcre

yum install pcre-devel

yum install zlib 

yum install zlib-devel

yum install openssl

yum install openssl-devel

Before installing the update can be performed, of course, this depends on your speed and processing speed slightly, some Big Brother is an update for an hour.

yum update


2.3 Extracting installation

Performs decompression operation

tar -zxvf nginx-xxx (you choose the version number) .tar.gz

Just unzip into the complete folder

cd /usr/local/nginx-xxx/

接下来configure & make & make install

./configure

make

make install

If this step is not wrong, then you have completed half the battle.


2.4 Configuration Service

cd /lib/systemd/system/

vim nginx.service

This should create a service profile nginx

press i finished writing the following configuration: wq

[Unit]
Description=nginx - high performance web server 
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

important point:

  • Path PIDFile is that nginx.pid file after you open the service will have the default logs directory in your nginx folder, while in the catalog as well as error.log, this document is useful, there are any errors, please a closer look at it, it certainly will help.

  • ExecStartPre this role is to test the configuration is correct before service starts, it depends on your taste add it.

  • ExecStart path is under your installation folder nginx / conf directory, is to load nginx.conf


2.5 Setting the boot, etc.

systemctl enable nginx.service

systemctl start nginx.service

During this period there are any problems, it is, it will restart the server.

You can see nginx service status by # systemctl status nginx.service this command. When Loaded: loaded, Active: When active (running), is complete. Quietly say, after you modify the configuration files need to be reloaded, The easy way is to restart the server. Of course, if your business does not allow frequent restart so is another matter. I draped myself like this play would restart it.


2.6 Configuring nginx

nginx default port 80 to listen, so do this step, you enter the ip of the server should be able to appear the welcome screen. Next we want to put up their own package.

npm run build, the company during the day to write something packaged, dist uploaded to the server.

vim modify nginx installation directory, conf / nginx.conf file

Under the server {listen} can be modified to a different port number, you can location / {root xxx;} modified to want to put your bag in place, the following is my configuration.

listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root dist;
            index index.html index.htm index.nginx-debian.html;
            try_files $uri $uri/ /index.html;
        }

Like this, just need to throw the package under nginx / dist folder, nginx can be read. Of course, this is a lazy approach, it is best to change the address of the other, but pay attention to rights issues, otherwise it will lead to all kinds of 500 error.

3. Windows configurations in nginx

3.1 differs under linux

In fact, many of the windows should be simple, because the more intuitive, but some people would rather die pits.

First or go to the official website to download your favorite version, note the nginx / Windows.

Here to directly extract your favorite directory.

Probably to this point will be very excited, but it should be noted, do not double-click nginx.exe .

But into the directory with powerShell / cmd, use the command start nginx run.

You can modify nginx.conf before you run, it is recommended to change the port number, and location, the following is my Windows configuration


        listen       6789;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root d:/repo/dist;
            index index.html index.htm index.nginx-debian.html;
            try_files $uri $uri/ /index.html;
        }
        
        location /excel {
           proxy_method POST;
           proxy_pass   http://*****:****/****$request_uri;
        }

After replacing the packetized dist d: / dist can, under repo native access only localhost: 6789, LAN access as long as ipconfig ip check strip port number.

3.2 Notes

Sometimes there will be a variety of unusual circumstances led to a variety of errors, first check error.log, where the error is very detailed.

  • If you encounter (123: The filename, directory name, or volume label syntax is incorrect) this error, you need to check the path is configured correctly. For example, copy the path name directly in Windows often make mistakes, but the name with some keywords, such as r, by default in Windows right oblique, will occur \ r recognized as an escape character, the path leading to inexplicable errors. Solution is simple, either all right oblique in double right oblique, left oblique or to use /.
  • On the computer has encountered an error colleague multiple processes. That is, use the following command

tasklist /fi "imagename eq nginx.exe"

There will be four processes, using nginx -s quit can only turn off the two processes.

Then you can kill the process, or can not appear correct results.

On Windows, the configuration of what I wrote is not very detailed, I read good article, here , we can refer to it.

Guess you like

Origin www.cnblogs.com/lizziuno/p/11982020.html