samoshi
By:
samoshi

Nginx config file for a website in FreeBsd and Linux are quite different?

April 29, 2017 1.1k views
Nginx FreeBSD

I know how to setup nginx in Linux. In FreeBsd I thought it'd exactly the same, except maybe a location of the config file. In Linux it's /etc/nginx/sites-available/default, in FreeBsd /usr/local/etc/nginx/nginx.conf

However, according to a tutorial here, in FreeBsd the config is also quite different: in Linux I'd have 2 sections of "server" for http and https. In FreeBsd there has to be "user" on the top level and number of workers. In other things which are pretty different. Not just paths, but the structure and sections.

Is that really so and they're indeed different?

1 comment
  • They aren't that different. Nginx also has these sections with "user" etc. they are just in some other config files. I am not sure what you would like to achieve, but you can probably just use the same config for your FreeBSD server ;)

4 Answers

Hi @samoshi
Like @CrypticDesigns says, the configuration is not different, but you're referencing two different config files.
On most Linux, the main Nginx config is /etc/nginx/nginx.conf. On most BSD it's /usr/local/etc/nginx/nginx.conf.
I don't have access to a BSD right now, but on Linux the server block configuration is located in /etc/nginx/sites-enabled/ (which is normally a symlink to /etc/nginx/sites-available/. My guess would be that BSD has the same setup, so that would be /usr/local/etc/nginx/sites-enabled.

@hansen thx. On Linux I use " /etc/nginx/sites-available/default" for the config of my website, what is it on FreeBsd?

oh, wait, I'll check if it's "/usr/local/etc/nginx/sites-enabled/default" later.

@hansen I haven't changed it after installation, it's the default one.

@hansen

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



load_module /usr/local/libexec/nginx/ngx_mail_module.so;
load_module /usr/local/libexec/nginx/ngx_stream_module.so;

#user  nobody;
worker_processes  1;

# This default error log path is compiled-in to make sure configuration parsing
# errors are logged somewhere, especially during unattended boot when stderr
# isn't normally logged anywhere. This path will be touched on every nginx
# start regardless of error log location configured here. See
# https://trac.nginx.org/nginx/ticket/147 for more info. 
#
#error_log  /var/log/nginx/error.log;
#

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/www/nginx;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
# 

  • @samoshi
    Okay, create the folder sites with command mkdir /usr/local/etc/nginx/sites
    Replace your nginx.conf with this (I've removed comments and added an include):

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        sendfile        on;
        keepalive_timeout  65;
    
        include       /usr/local/etc/nginx/sites/*;
    }
    

    Now add you server blocks to the /usr/local/etc/nginx/sites/ folder and restart Nginx after every configuration change.

Have another answer? Share your knowledge.