Nginx - 虚拟主机无法正常工作

Nginx - 虚拟主机无法正常工作

我购买了 macOS Big Sur,并尝试在其上安装 php + nginx,但一直出现问题,无法正确添加我的域。我有以下配置:

usr/local/etc/php/7.3/php-fpm.d/www.conf

; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]

; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr/local/Cellar/[email protected]/7.3.31) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = pcyrkl01
group = staff

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9073

我尝试了不同的配置,但尽管搜索了几个小时,我仍找不到问题的解决方案。

我的虚拟主机为 admin.local

server {

        # For https
        listen 443 ssl;
        listen [::]:443 ssl;
        ssl_certificate /Users/pcyrkl01/ssl/default.crt;
        ssl_certificate_key /Users/pcyrkl01/ssl/default.key;

        server_name admin.local;
        root /Users/pcyrkl01/sites/admin.local/web_admin;
        index index.php index.html index.htm;

        location / {
          try_files $uri @rewriteapp;
        }

        location @rewriteapp {
            rewrite ^(.*)$ /app_dev.php/$1 last;
        }

        location ~ ^/(app|app_dev|config|index)\.php(/|$) {
            fastcgi_pass 127.0.0.1:9073;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fixes timeouts
            fastcgi_read_timeout 600;
            fastcgi_param HTTPS off;
        }

        location ~* \.(eot|ttf|woff|woff2)$ {
            add_header Access-Control-Allow-Origin *;
        }

        error_log /Users/pcyrkl01/web_log/symfony_error.log;
        access_log /Users/pcyrkl01/web_log/symfony_access.log;
    }

本地后端

 server {
    
            # For https
            listen 443 ssl;
            listen [::]:443 ssl;
            ssl_certificate /Users/pcyrkl01/ssl/default.crt;
            ssl_certificate_key /Users/pcyrkl01/ssl/default.key;
    
            server_name admin.local;
            root /Users/pcyrkl01/sites/admin.local/web;
            index index.php index.html index.htm;
    
            location / {
              try_files $uri @rewriteapp;
            }
    
            location @rewriteapp {
                rewrite ^(.*)$ /app_dev.php/$1 last;
            }
    
            location ~ ^/(app|app_dev|config|index)\.php(/|$) {
                fastcgi_pass 127.0.0.1:9073;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fixes timeouts
                fastcgi_read_timeout 600;
                fastcgi_param HTTPS off;
            }
    
            location ~* \.(eot|ttf|woff|woff2)$ {
                add_header Access-Control-Allow-Origin *;
            }
    
            error_log /Users/pcyrkl01/web_log/symfony_error.log;
            access_log /Users/pcyrkl01/web_log/symfony_access.log;
        }

我的 nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root html;
            fastcgi_intercept_errors on;
            fastcgi_pass   127.0.0.1:9073;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            # Again, you may need to change this path, it's based on a brew install.
            include /usr/local/etc/nginx/fastcgi_params;
        }

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           root           html;
            fastcgi_pass   127.0.0.1:9073;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}

我的文件权限

 -rw-r--r--    1 pcyrkl01  staff   1.9K Oct 20 15:03 Dockerfile
-rw-r--r--    1 pcyrkl01  staff   2.3K Oct 20 15:03 Dockerfile73
-rw-r--r--    1 pcyrkl01  staff   2.2K Oct 20 15:03 README.md
drwxr-xr-x    9 pcyrkl01  staff   288B Oct 20 15:03 app
drwxr-xr-x    4 pcyrkl01  staff   128B Oct 20 15:15 bin
-rw-r--r--    1 pcyrkl01  staff   4.0K Oct 20 15:03 composer.json
-rw-r--r--    1 pcyrkl01  staff   345K Oct 20 15:03 composer.lock
-rwxr-xr-x    1 pcyrkl01  staff   1.8M Oct 20 15:03 composer.phar
drwxr-xr-x    3 pcyrkl01  staff    96B Oct 20 15:03 deploy
-rw-r--r--    1 pcyrkl01  staff   662B Oct 20 15:03 deploy.php
-rw-r--r--    1 pcyrkl01  staff   3.6K Oct 20 15:03 deploy_aws.php
-rw-r--r--    1 pcyrkl01  staff    12K Oct 20 15:03 deploy_test.php
-rw-r--r--    1 pcyrkl01  staff   787B Oct 20 15:03 docker-compose.dev.yml
drwxr-xr-x    5 pcyrkl01  staff   160B Oct 20 15:03 docs
drwxr-xr-x    6 pcyrkl01  staff   192B Oct 20 15:03 front
-rw-r--r--    1 pcyrkl01  staff    13K Oct 20 15:03 gulpfile.js
-rw-r--r--    1 pcyrkl01  staff   1.5K Oct 20 15:03 nagios.php
drwxr-xr-x  677 pcyrkl01  staff    21K Oct 20 15:12 node_modules
-rw-r--r--    1 pcyrkl01  staff   287K Oct 20 15:12 npm-shrinkwrap.json
-rw-r--r--    1 pcyrkl01  staff   290K Oct 20 15:03 package-lock.json
-rw-r--r--    1 pcyrkl01  staff   769B Oct 20 15:03 package.json
-rw-r--r--    1 pcyrkl01  staff   1.3K Oct 20 15:03 phpunit.xml.dist
drwxr-xr-x    5 pcyrkl01  staff   160B Oct 20 15:03 src
drwxr-xr-x    6 pcyrkl01  staff   192B Oct 20 15:03 tests
drwxr-xr-x    6 pcyrkl01  staff   192B Oct 20 15:15 var
drwxr-xr-x   65 pcyrkl01  staff   2.0K Oct 20 15:15 vendor
drwxr-xr-x   31 pcyrkl01  staff   992B Oct 20 15:15 web
drwxr-xr-x    7 pcyrkl01  staff   224B Oct 20 15:09 web_admin
drwxr-xr-x    6 pcyrkl01  staff   192B Oct 20 15:03 web_api

在 /etc/hosts 中我添加了: 127.0.0.1 admin.local local.backend

酿造服务列表

nginx   started pcyrkl01 /Users/pcyrkl01/Library/LaunchAgents/homebrew.mxcl.nginx.plist
[email protected] started pcyrkl01 /Users/pcyrkl01/Library/LaunchAgents/[email protected]

问题是两个主机都向我打开了网站,而不是位置/usr/local/var/www,而不是我的-Users/pcyrkl01/sites/local.admin/web或web_admin

相关内容