Configure Nginx under Mac

Source: Internet
Author: User
Tags epoll sendfile

Nginx is a high-performance HTTP and reverse proxy server, but also a IMAP/POP3/SMTP server, let us understand the use of nginx.

Installing Nginx

Using Brew to install Nginx

install nginx

Wait for the installation of Nginx, we can do the Nginx configuration after installation.

Configure Nginx

The configuration files for Mac Nginx are:

/usr/local/etc/nginx/nginx.conf

Open the nginx.conf, you can do the relevant configuration.
Nginx Configuration Detailed:

#define Nginx running users and user groups to specify NGINX worker process running user and user group, by default run by nobody accountUser * * *;#the number of nginx processes, the recommended setting is equal to the total CPU core number. Worker_processes 4;#Global error log definition type, [Debug | info | notice | warn | error | crit], where the debug output log is most verbose and crit output log is minimalError_logLogs/error.Loginfo;#a process file that specifies the location of the storage file for the process IDPID Logs/nginx.pid;#a Nginx process opens the maximum number of file descriptors, the theoretical value should be the maximum number of open files (System value ulimit-n) and the number of nginx process, but the Nginx allocation request is not uniform, so we recommend that the value of ulimit-n consistent, you can use the command " Ulimit-n 65535 "to set other values. Worker_rlimit_nofile 4864;#Maximum number of operating modes and connectionsEvents {#Reference event model, use [kqueue | rtsig | epoll |/dev/poll | select | poll]; EPOLL model is a high-performance network I/O model in Linux version 2.6 and above, and if it runs on FreeBSD, it Use the Kqueue model.      UseEpoll;#Mac platform with Kqueue, for Linux system, epoll working mode is the first choice    #The worker_connections is used to define the maximum number of connections per session of Nginx, that is, the maximum number of requests received by the front end, which defaults to 1024. The maximum number of client connections is determined by worker_processes and Worker_connections, which is max_clients=worker_processes*worker_connections, when acting as a reverse proxy, Max_ Clients changed to: max_clients = worker_processes * WORKER_CONNECTIONS/4. The maximum number of connections for a process is limited by the maximum number of open files for the Linux system process, and the worker_connections settings are not valid until the operating system command "Ulimit-n 65536" is executedWorker_connections 1024;}#setting up an HTTP serverhttp {#to use the MIME type of the set file, type the Mime.type file definition in the profile directory to tell Nginx to identify the file type.     includeMime.types; Default_type Application/octet-stream;#Default File Type    #charset utf-8; #默认编码    #used to set the format of the log, and what parameters to record, which is set to main, just for Access_log to record this type    #Log_format main ' $remote _addr-$remote _user [$time _local] "$request" '    #' $status $body _bytes_sent ' $http _referer '    #' "$http _user_agent" "$http _x_forwarded_for";Sendfile on;#Open the efficient file transfer mode, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, for the normal application is set to ON, if used for downloading and other applications such as disk IO heavy load application, can be set to off to balance disk and network I/O processing speed, Reduce the load on the system. Note: If the picture does not appear normal, change this to off. AutoIndex on;#Open Directory list access, appropriate to download the server, the default shutdown. Tcp_nopush on;#Prevent network congestionTcp_nodelay on;#Prevent network congestionKeepalive_timeout 120;#Long connection time-out, unit is seconds#fastcgi related parameters are designed to improve the performance of the site: Reduce resource usage and improve access speed. The following parameters can be understood by literal means. Fastcgi_connect_timeout 300; Fastcgi_send_timeout300; Fastcgi_read_timeout300;    Fastcgi_buffer_size 64k; Fastcgi_buffers464k;    Fastcgi_busy_buffers_size 128k; Fastcgi_temp_file_write_size 128k;#gzip Module Settingsgzip on;#turn on gzip compression outputGzip_min_length 1k;#Minimum compressed file sizeGzip_buffers 4 16k;#Compression BuffersGzip_http_version 1.0;#compressed version (default 1.1, front End If squid2.5 please use 1.0)Gzip_comp_level 2;#compression LevelGzip_types text/plain application/x-javascript text/css application/XML; #compression type, the default already contains text/html, so the following will not have to write, write up will not have a problem, but there will be a warn. gzip_vary on; #limit_zone crawler $binary _remote_addr 10m; #开启限制IP连接数的时候需要使用Upstream Blog. ha97.com {#Upstream load balancing, weight is a weight that can be defined according to machine configuration. The Weigth parameter represents weights, and the higher the weight, the greater the probability of being allocated. Server 192.168.80.121:80 weight=3; Server192.168.80.122:80 weight=2; Server192.168.80.123:80 weight=3; }    #configuration of the virtual hostserver {#Listening PortListen 80; #domain names can have multiple, separated by spacesSERVER_NAME www.***.com * * *.com; Index index. HTML index.htm Index.PHP; #represents the full root Web root directory within this entire server virtual host. Note that you want to differentiate it from the definition below locate {}Root/data/www/***;             location/mp/{Proxy_pass http://127.0.0.1:8080;        Proxy_set_header Host $host;             } location/{Proxy_pass http://192.168.200.248:80;        Proxy_set_header Host $host;    } add_header Access-control-allow-origin "*"; }}

Later, add nginx load balancer and reverse proxy.

Nginx Common Commands

Start Nginx:

sudo nginx

Determine if the configuration file is correct

sudo nginx-t

To stop Nginx:

sudo nginx-s stop

Restart Nginx:

sudo nginx-s reload

Configure Nginx under Mac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.