
本文共 5405 字,大约阅读时间需要 18 分钟。
Nginx���������������������
1. Nginx���������
��� CentOS 6.x ������������������������ Nginx ���available, ���������������������������������:
������ Nginx ���������������������http://nginx.org/en/linux_packages.html#stable
������ CentOS 6.x ��� Nginx ���������������������
������������������������ RPM ���������������������http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
������ yum ���������������
sudo yum install nginx-release-centos-6-0.el6.ngx.noarch.rpm -y
������������������������������ nginx ��������������������������������������������������������� Nginx ��������� ������ Nginx ���������
������������������������������������������������������ Nginx���sudo yum install nginx -y
������������������������Nginx ��������������������������� CentOS ������������������������������������������������������������
2. Nginx ���������������
������������������Nginx ������������������������ /etc/nginx/nginx.conf
��������������������������������� Nginx ���������������������
- ���������������
sudo service nginx start
- ���������������
sudo service nginx stop
- ���������������
sudo service nginx restart
- ���������������������
sudo service nginx reload
- ���������������������
sudo service nginx status
��������������������� Nginx ������������������������������������������������������������������������
3. Nginx ���������������
Nginx ������������������������ <\/etc\/nginx\/nginx.conf>
������������������������������������������������������������������
���������������������
Nginx ������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������/etc/nginx/nginx.conf
������������������������������������������������������������������������ ���������������������������
������������������������������������������������������������������������nginx.conf
��������� sudo find / -name "nginx.conf"
���������������������
������������������������������������������������������������������������������sudo nginx -t
������������������������������������������������������������������������ 4. Nginx ���������������
Nginx ������������������������ directives������������ ������������������������������������������������������������������������������������bracketed directives������
1. ���������������������
listen 80; # ���������������������
2. ������������������
http { # ������ server ��������� server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; } }}
block ��������������� server
��� location
��������������������������������������������������������������������������������������������������������� Nginx ���������
5. ���������������
��������������������������� IP ���������������Nginx ������������������������������������������������������������������������������������������������������������������������
������������������������������������������
���������������������������www.525.life
��� admin.525.life
��������������������������������������� IP 123.123.123.123
���
������������������
www.525.life
��������������� 8880admin.525.life
��������������� 8881
������������ Nginx ������������������������������
server { listen 80; server_name www.525.life; location / { proxy_pass http://localhost:8880; # ��������������������������� }}server { listen 80; server_name admin.525.life; location / { proxy_pass http://localhost:8881; # ��������������������������� }}
������������������������
������������������������������������������������ admin.525.life
������Nginx ���������������������������������������������������������������������
server { listen 80; server_name *.525.life; # ��������������� .525.life ��������������� location / { proxy_pass http://localhost:8880; }}
��������������������������������������������� www.525.life
���������������������������
6. 301 ������������
��������������������� www
������������������������ www
������������������������ Nginx ������������������������������
server { listen 80; server_name 525.life; location / { rewrite ^/ http://www.525.life$request_uri permanent; # 301 ��������� }}
���������������������
��������������������������������������������������� rewrite
������������������
server { listen 80; server_name blog.example.com; rewrite ^/(.*) https://www.example.com/blog/$1 permanent; # ��������� https://www.example.com/blog}
7. 404 ������������
��������������� URL ������������������������������������������������������ 404 ���������������
server { listen 80; server_name example.com; error_page 404 /404.html;}
���������������������
������������������������������������ 404���������������������������
server { listen 80; server_name example.com; error_page 404 /custom_404.html;}
8. ������ IP ������������
������������������ IP ��������������������������������������������������������������������������������������������������� Nginx ������������������������������
server { listen 80 default_server; server_name _; # ������������ IP ������ return 403; # ������ 403 Forbidden ������}
������������������������������������������������������ Nginx ������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
