1 配置 nginx.conf

 

server {
         listen       80 ;
       server_name  www.localhost.com;
        root         /usr/share/nginx/html;
        index index.php index.html index.htm;
        charset utf-8;
        include /etc/nginx/default.d/*.conf;
        location / {
        }
    }

2:配置www.cmh.com项目  conf.d/cmh.conf

server {
        listen       80;
        server_name   www.cmh.com;
        charset utf-8;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

         root  /usr/share/nginx/html/project;
         index index.php index.html index.htm;

        location / {
                root         /usr/share/nginx/html/project;
                index index.php index.html index.htm;
        }
    }

3:配置php解析 default.d/php.conf

location ~ .php$ {
        try_files $uri =404;
#        root /usr/share/nginx/html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi.conf;
}

       error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

4 添加域名解析  /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  www.localhost.com
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.33.10    www.cmh.com

 

5 主机访问vagrant里域名

修改C:\Windows\System32\drivers\etc\hosts

添加 

192.168.33.10 www.cmh.com

192.168.33.10 www.localhost.com

 

user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;
events {    worker_connections 1024;}
http {    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;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.    # See http://nginx.org/en/docs/ngx_core_module.html#include    # for more information.    include /etc/nginx/conf.d/*.conf;
    server {         listen       80 ;#        listen       80 default_server;#        listen       [::]:80 default_server;#        server_name  _;       server_name  www.localhost.com;        root         /usr/share/nginx/html;        index index.php index.html index.htm;        charset utf-8;
        # Load configuration files for the default server block.        include /etc/nginx/default.d/*.conf;
        location / {        }
#        error_page 404 /404.html;#            location = /40x.html {#        }
#        error_page 500 502 503 504 /50x.html;#            location = /50x.html {#        }
#       location ~ .php$ {#            try_files $uri =404;#            root /usr/share/nginx/html;#            fastcgi_pass 127.0.0.1:9000;#            fastcgi_index index.php;#            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#            include fastcgi.conf;#        }
    }

 

posted on 2020-05-01 21:16  ksy_c  阅读(815)  评论(0)    收藏  举报