Skip to main content

Nginx 3

Vhost config

ERR_ICANN_NAME_COLLISION when trying to use localhost .dev in Chrome

Lỗi liên quan đến tên vhost:
1. /etc/hosts kiểm tra
2. /etc/nginx/sites-available  và /etc/nginx/sites-enabled xem tương ứng và chuẩn chưa. Ko thì unlink rồi tạo lại. Lưu ý khi tạo soft link cần chỉ định absolute path (y thì chưa rõ).
sudo ln -s /etc/nginx/....          /etc/nginx/......

Lỗi config server (vhost) hay server block. block chắc đúng cho config / 1 file như CentOS còn Ub (debian) thì tách ra file khác nhau roài.

Để ý: servername cần thêm cả www. ở đầu ko thì hay gặp lỗi nhiểu vhost loạn dẫn đến redirect về default vhost. Nó cứ bay về trang đầu tiên cài vhost.
Lỗi này thì Apache cũng vậy vì cơ chế set vhost là same.

ví dụ cho phpMyAdmin:

nickfarrow:playbuzz$ cat /etc/nginx/sites-available/padm.local.dev 
server {
        listen       80;
    #ssl on;
    #ssl_certificate /etc/nginx/ssl/server.crt;
    #ssl_certificate_key /etc/nginx/ssl/server.key;

        server_name www.padm.local.dev;
        root /var/www/phpMyAdmin;
        index index.php;

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

Trường hợp sub-domain: vd yoursite.com và padm.yoursite.com:
Thì yoursite.com cần thêm default_server sau listen. Lý do là nếu ko domain chính sẽ đc redirect đến, ngoài ra thì m ko biết ng nhân khác.
server {
          listen 80 default_server;
          servername www.subdomain.yoursite.com
....

Bonus: alias cho nginx phỏng theo apache:
alias apcrst='sudo service apache2 restart'
alias apcrld='sudo service apache2 reload'
alias apctest='sudo apachectl configtest'
alias tailalob='tail -f /var/log/apache2/abc_error.log'
alias countapc='ps aux |grep apache | wc -l'

alias ngrst='sudo service nginx restart'
alias ngrld='sudo service nginx reload'
alias ngtest='sudo nginx -t'


Comments

Popular posts from this blog

Rand mm 10

https://stackoverflow.com/questions/2447791/define-vs-const Oh const vs define, many time I got unexpected interview question. As this one, I do not know much or try to study this. My work flow, and I believe of many programmer is that search topic only when we have task or job to tackle. We ignore many 'basic', 'fundamental' documents, RTFM is boring. So I think it is a trade off between the two way of study language. And I think there are a bridge or balanced way to extract both advantage of two method. There are some huge issue with programmer like me that prevent we master some technique that take only little time if doing properly. For example, some Red Hat certificate program, lesson, course that I have learned during Collage gave our exceptional useful when it cover almost all topic while working with Linux. I remember it called something like RHEL (RedHat Enterprise Linux) Certificate... I think there are many tons of documents, guide n books about Linux bu

Martin Fowler - Software Architecture - Making Architecture matter

  https://martinfowler.com/architecture/ One can appreciate the point of this presentation when one's sense of code smell is trained, functional and utilized. Those controlling the budget as well as developer leads should understand the design stamina hypothesis, so that the appropriate focus and priority is given to internal quality - otherwise pay a high price soon. Andrew Farrell 8 months ago I love that he was able to give an important lesson on the “How?” of software architecture at the very end: delegate decisions to those with the time to focus on them. Very nice and straight-forward talk about the value of software architecture For me, architecture is the distribution of complexity in a system. And also, how subsystems communicate with each other. A battle between craftmanship and the economics and economics always win... https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011 1. Independent of Frameworks 2. Testable 3. Indepe