美文网首页
nginx 配置

nginx 配置

作者: 学生黄哲 | 来源:发表于2020-12-14 10:53 被阅读0次

    MAC nginx默认路径

    配置文件路径:
    /usr/local/etc/nginx/nginx.conf
    
    错误日志路径:
    /usr/local/var/log/nginx/error.log
    

    1、nginx访问配置

    server {
        listen 3066;
        server_name _;
        root ;    #路径
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
            # try_files $uri $uri/ =404;
        }
    }
    

    2、代理本地3000端口到3066端口

    server {
      listen 3066;
      server_name _;
      index index.html index.htm index.php default.html default.htm default.php;
      location / {
          proxy_set_header host $host;
          proxy_set_header X-real-ip $remote_addr;
          proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
          proxy_pass http://127.0.0.1:3000/;
      }
    }
    

    3、代理网络端口和本地端口到3066解决跨域问题

    server {
      listen 3061;
      server_name _;
      index index.html index.htm index.php default.html default.htm default.php;
      location /api/ {
          proxy_set_header host $host;
          proxy_set_header X-real-ip $remote_addr;
          proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
          #网络端口
          proxy_pass http://8.131.75.244:8801/;
      }
      location / {
          proxy_set_header host $host;
          proxy_set_header X-real-ip $remote_addr;
          proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
          #本地3000端口
          proxy_pass http://127.0.0.1:3000/;
      }
    }
    

    4、nginx域名配置

    server {
        listen 443 ssl;
        server_name xxx.com;
    
        ssl_certificate crt路径;
        ssl_certificate_key key路径;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
    
        root 路径;
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #root /code/app1/build;
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
            # try_files $uri $uri/ =404;
        }
        #反向代理api解决跨域问题
        location /api/ {
            proxy_set_header host $host;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
            #api端口 
            proxy_pass http://127.0.0.1:8801;
        }
    }
    

    相关文章

      网友评论

          本文标题:nginx 配置

          本文链接:https://www.haomeiwen.com/subject/sdfvgktx.html