使用Nginx为MacOS设置自动虚拟主机

时间:2019-04-21 06:43:02

标签: macos nginx

我一直试图在MacOS上本地设置一个环境,该环境允许我向/var/www/添加一个新项目文件夹,它将项目名称作为主机名,并将其用作通过端口5000代理的端口80。 / p>

当前,在浏览器中转到localhost会进入欢迎的nginx您好默认页面,但是当我尝试转到testsite.local.dev时,我从浏览器ERR_CONNECTION_REFUSED拒绝了连接

这是我的nginx.conf和我的wildcard.conf配置文件:

nginx.conf

user <user> staff;
worker_processes 1;
error_log /var/log/nginx.error.log; 
error_log /var/log/nginx.error.log notice;
error_log /var/log/nginx.error.log info;
pid /var/tmp/nginx.pid;
events { 
  worker_connections 128; 
}

http { 
  include mime.types; 
  default_type application/octet-stream;
  #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';
  #access_log /var/log/nginx.access.log main;
  sendfile on;
  #tcp_nopush on;
  #keepalive_timeout 0;
  keepalive_timeout 65;
  #gzip on;
  server { 
    server_name localhost; 

    #access_log /var/log/nginx.localhost.access.log main;


    #error_page 404 /404.html;
    # redirect server error pages to the static page /50x.html 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
        root html; 
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ { 
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_buffers 256 128k; 
        fastcgi_connect_timeout 300s; 
        fastcgi_send_timeout 300s; 
        fastcgi_read_timeout 300s; 
        include fastcgi_params; 
    }
    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one
    location ~ /\.ht {
      deny all; 
    } 
  }

  proxy_buffer_size   128k;
  proxy_buffers   4 256k;
  proxy_busy_buffers_size   256k;

  include /usr/local/etc/nginx/sites-available/*.conf;
}

wildcard.conf

server {
  listen 80;
  server_name ~^(?<sname>.+)$;
  root /var/www/$sname/html/;

  index index.html index.htm index.php;

  charset utf-8;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
    proxy_pass         http://127.0.0.1:5000;
  }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }

  access_log /var/log/nginx/$sname-access.log;

  error_page 404 /index.php;

  sendfile off;

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
  }

  location ~ /\.ht {
    deny all;
  }
}

0 个答案:

没有答案