Nginx-------Nginx的安装和多域名配置
发布日期:2021-05-10 01:24:07 浏览次数:17 分类:精选文章

本文共 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 ��������������� 8880
    • admin.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 ������������������������������������������������������������������������������������

    上一篇:负载(Load)分析及问题排查
    下一篇:centos启动、关闭tomcat

    发表评论

    最新留言

    路过,博主的博客真漂亮。。
    [***.116.15.85]2025年04月05日 08时29分22秒