Skip to content

Instantly share code, notes, and snippets.

@devthue
Last active October 18, 2016 15:36
Show Gist options
  • Save devthue/982be76763946099b2118dc792db4a7f to your computer and use it in GitHub Desktop.
Save devthue/982be76763946099b2118dc792db4a7f to your computer and use it in GitHub Desktop.
Config Nginx
  • Chỉnh sửa file /etc/hosts ngoài máy thật
127.0.0.1 bigseo.dev
  • Thêm 1 file nginx config mới /etc/nginx/conf.d với tên file bigseo.dev.conf nội dung:

Thay đổi:

  • server_name: Tên domain
  • root_path : Đường dẫn đến folder chứa index.php
server {

    listen   80;
    server_name bigseo.dev;
    client_max_body_size 100m;
    index index.php;
    set $root_path '/home/php/bigseo/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        # fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param APPLICATION_ENV "development";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }

}
  • Gõ câu lệnh nginx -t để kiểm tra cấu hình đúng hay chưa:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • Sau khi test thành công thì restart lại NGINX. Bất kỳ thay đổi nào trong file cấu hình NGINX thì phải restart lại NGINX server: service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment