(13: Permission denied) while connecting to upstream:[nginx]

I had a similar issue getting Fedora 20, Nginx, Node.js, and Ghost (blog) to work. It turns out my issue was due to SELinux.

This should solve the problem:

setsebool -P httpd_can_network_connect 1

Details

I checked for errors in the SELinux logs:

sudo cat /var/log/audit/audit.log | grep nginx | grep denied

And found that running the following commands fixed my issue:

sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp

References:

http://blog.frag-gustav.de/2013/07/21/nginx-selinux-me-mad/

https://wiki.gentoo.org/wiki/SELinux/Tutorials/Where_to_find_SELinux_permission_denial_details

http://wiki.gentoo.org/wiki/SELinux/Tutorials/Managing_network_port_labels

http://www.linuxproblems.org/wiki/Selinux

Source: https://stackoverflow.com/a/24830777/4353123

How can I get mv (or the * wildcard) to move hidden files?

You can do this :

shopt -s dotglob
mv /tmp/home/rcook/* /home/rcook/

You can put

shopt -s dotglob

in your ~/.bashrc if you want it to be the default.

See http://mywiki.wooledge.org/glob


Another approach to copy the dot files:

mv /tmp/home/rcook/.[!.]* /home/rcook/

Don’t use the pattern ..* as it matches .. (pointer to the parent directory). If there are files whose name begin with two dots (..something), also use the pattern ..?*.

MySQL Orderby a number, Nulls last

Currently I am doing a very basic OrderBy in my statement.

SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC

The problem with this is that NULL entries for ‘position’ are treated as 0. Therefore all entries with position as NULL appear before those with 1,2,3,4. eg:

NULL, NULL, NULL, 1, 2, 3, 4

Is there a way to achieve the following ordering:

1, 2, 3, 4, NULL, NULL, NULL.

MySQL has an undocumented syntax to sort nulls last. Place a minus sign (-) before the column name and switch the ASC to DESC:

SELECT * FROM tablename WHERE visible=1 ORDER BY -position DESC, id DESC

It is essentially the inverse of position DESC placing the NULL values last but otherwise the same as position ASC.

A good reference is here http://troels.arvin.dk/db/rdbms#select-order_by

Source: https://stackoverflow.com/a/8174026/4353123

Register Service Provider and assign a Facade alias programmatically in Laravel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php 

namespace MyPackage\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;

class MyPackageServiceProvider extends ServiceProvider
{
//...

public function register()
{
//set up facade
AliasLoader::getInstance()->alias('MyFacade', 'MyPackage\Facades\MyFacade');
}

//...
}

Git command bookmark

Remove directory from remote repository after adding them to .gitignore

The rules in your .gitignore file only apply to untracked files. Since the files under that directory were already committed in your repository, you have to unstage them, create a commit, and push that to GitHub:

1
2
3
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master

You can’t delete the file from your history without rewriting the history of your repository - you shouldn’t do this if anyone else is working with your repository, or you’re using it from multiple computers. If you still want to do that, you can use git filter-branch to rewrite the history - there is a helpful guide to that here.

Additionally, note the output from git rm -r --cached some-directory will be something like:

1
2
3
4
rm 'some-directory/product/cache/1/small_image/130x130/small_image.jpg'
rm 'some-directory/product/cache/1/small_image/135x/small_image.jpg'
rm 'some-directory/.htaccess'
rm 'some-directory/logo.jpg'

The rm is feedback from git about the repository; the files are still in the working directory.

Tạo Swap trong Linux

Swap là gì?

Swap là RAM ảo, nó sử dụng ổ đĩa của máy tính làm RAM. Khi hệ thống Linux hết RAM, các tài nguyên không hoạt động sẽ được chuyển sang vùng RAM ảo này để giải phóng bớt tài nguyên của RAM vật lý.

Không gian Swap có thể ở dạng phân vùng vật lý hoặc là tệp swap. Trong hầu hết các trường hợp, khi hệ thống Linux chạy trên máy ảo, nó sẽ không có sẵn phân vùng swap. Vì vậy lựa chọn duy nhất là tạo swap file. Bài này sẽ hướng dẫn các bạn cách tạo swap file trên VPS Linux.

Cách tạo Swap File

Thực hiện theo các bước bên dưới để tạo file Swap với dung lượng 1GB. Nếu bạn muốn thêm 2GB thay vì 1GB, hay thay thế giá trị 1GB thành 2GB.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×