Skip to content

Instantly share code, notes, and snippets.

@therealechan
Last active July 18, 2016 06:37
Show Gist options
  • Save therealechan/412cb7ab3d02fac2b84c to your computer and use it in GitHub Desktop.
Save therealechan/412cb7ab3d02fac2b84c to your computer and use it in GitHub Desktop.
config multiple website with Nginx

in /opt/nginx/conf/nginx.conf, to include the folder call sites-enabled

http { ... include /opt/nginx/conf/sites-enabled/*; ... }

Then mkdir sites-enabled and sites-available folder in /opt/nginx/conf/

in sites-available to create site config

example:

$ sudo vi example.com

server {
    listen       80;
    server_name  example.com;

    root /var/www/example_site/current/public/;
    passenger_enabled on;
    #passenger_start_timeout 300;

    rails_env production;
    add_header X-Frame-Options ALLOWALL;
    ignore_invalid_headers off;

    #charset koi8-r;

    access_log  /var/www/example_site/shared/log/nginx_access.log;
    error_log  /var/www/example_site/shared/log/nginx_error.log  error;


    #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   html;
    }
}

Also you need to create a link file $ ln -s /opt/nginx/conf/sites-available/example.com /opt/nginx/conf/sites-enabled/

Reload the config sudo /opt/nginx/sbin/nginx -s reload

Restart nginx sudo service nginx restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment