Answers for "how to config nginx"

0

How to Configure NGINX

1. Directives, Blocks, and Contexts
File: /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
       . . .
}

http {
       . . .
}

2. The http Block
File: /etc/nginx/nginx.conf
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
3. Server Blocks
File: /etc/nginx/conf.d/example.com.conf
server {
    listen         80 default_server;
    listen         [::]:80 default_server;
    server_name    example.com www.example.com;
    root           /var/www/example.com;
    index          index.html;
    try_files $uri /index.html;
}
4. Listening Ports
File: /etc/nginx/conf.d/example.com.conf
server_name   example.com www.example.com;
5. Location Blocks
location / { }
location /images/ { }
location /blog/ { }
location /planet/ { }
location /planet/blog/ { }

6. Location Root and Index
location / {
    root html;
    index index.html index.htm;
}
Posted by: Guest on June-03-2021

Browse Popular Code Answers by Language