Installation and Configuration brew with nginx

Installation Process

As used herein brew to install the software.

  • installation
brew install nginx
  • Review the installation information (frequently used, such as viewing the installation directory, etc.)
sudo brew info nginx


Once installed, mainly to see the brew to install nginx gone, the default is to install/usr/local/etc/nginx/nginx.conf


Record commonly used commands

  • View nginx version
nginx -v
  • Start nginx Service
brew services start nginx

Access: http://localhost:8080/After seeing the success of the following is the start.

If it does not succeed, look at the process ps -ef|grep nginx:

To see if there are three processes, if the process does not start, promise me to go first to an error file, please! Go to the main configuration file /usr/local/etc/nginx/nginx.conf, the error logging turned on, believe me, you see the speed error log resolved, Baidu faster than you must check.

  • Reload nginx
# 答应我,有任何一丁点修改过nginx的配置文件后,都第一时间重新加载一遍nginx  好吗!
# 答应我,有任何一丁点修改过nginx的配置文件后,都第一时间重新加载一遍nginx  好吗!
# 答应我,有任何一丁点修改过nginx的配置文件后,都第一时间重新加载一遍nginx  好吗!不然你就没法使 你修改的过的功能。

nginx -s reload
  • Close nginx Service
brew services stop nginx

  • Stop nginx
nginx -s stop

Typical configuration

In the /usr/local/etc/nginx/nginx.confmain configuration file, a configuration attribute contains, as follows:

# 省略...
include servers/*;
# 意思是加载当前目录下 .servers文件夹内的配置文件,都会被加载进来

In the /usr/local/etc/nginx/serverslower path, configured with a forwarding service, the file is called localhost_80.conf, as follows:

server {
        listen        80;
        server_name  localhost;
        root   "/Users/thoth/program/nginxweb";
        location / {
            index index.php index.html;
            error_page 400 /error/400.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 500 /error/500.html;
            error_page 501 /error/501.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            error_page 504 /error/504.html;
            error_page 505 /error/505.html;
            error_page 506 /error/506.html;
            error_page 507 /error/507.html;
            error_page 509 /error/509.html;
            error_page 510 /error/510.html;
            autoindex  off;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

This can serve as your template, you change it server_name, rootyou can.

        server_name  www.test.com;
        root   "/Users/thoth/program/testdir";

reference

https://www.jianshu.com/p/6c7cb820a020
http://jalan.space/2017/01/12/2017-01-13-mac-os-nginx/

Guess you like

Origin www.cnblogs.com/mysticbinary/p/12633233.html