Home >Backend Development >PHP Tutorial >Server mac installation nginx environment

Server mac installation nginx environment

WBOY
WBOYOriginal
2016-08-08 09:27:251011browse

I came into contact with the proxy server some time ago and set up an nginx environment through trial and error. Next, I will introduce you to the basic steps of installing the nginx environment on mac.

  1. This article uses homebrew to install nginx. First open the terminal and enter the installation command line
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    to install homebrew. Official website: http://brew.sh/.
    If the following prompt appears, it means that nginx has been installed on the mac or the last failure to install nginx left remnants
    It appears Homebrew is already installed. If your intent is to reinstall you
    should do the following before running this installer again:
        rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
    Enter the deletion command line as prompted:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
    After deletion, enter the installation command line.
  2. After downloading homebrew, homebrew will be installed automatically. Use brew to install nginx with one click
    brew install nginx
  3. After installation, test whether nginx can work normally
    nginx -t
    正确提示:nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
             nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
  4. If there is a prompt that the permissions are insufficient, you need to open the files under nginx Permissions
    chmod 777 file
    file为需要开放权限的文件路径
  5. After nginx can work normally, first change the nginx configuration file
    vim /usr/local/etc/nginx/nginx.conf
    server {
            listen       9999(自定义端口号);
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   /Users/loki/Desktop/web/(需要部署应用的文件路径);
                index  index.html index.htm;
            }
  6. After the configuration file has been changed, start nginx
    sudo nginx
  7. Basic usage of nginx
    nginx -s reload    #重新加载配置
    nginx -s reopen   #重启
    nginx -s stop       #停止
    nginx -s quit        #退出
    选项:
        -?,-h           : 打开帮助信息
        -v              : 显示版本信息并退出
        -V              : 显示版本和配置选项信息,然后退出
        -t              : 检测配置文件是否有语法错误,然后退出
        -q              : 在检测配置文件期间屏蔽非错误信息
        -s signal       : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
        -p prefix       : 设置前缀路径(默认是:/usr/local/Cellar/nginx/1.2.6/)
        -c filename     : 设置配置文件(默认是:/usr/local/etc/nginx/nginx.conf)
        -g directives   : 设置配置文件外的全局指令

The above introduces the server mac installation nginx environment, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn