首页 > 其他 > 详细

配置nginx域名

时间:2020-05-01 21:53:24      阅读:65      评论:0      收藏:0      [点我收藏+]

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

 

配置nginx域名

原文:https://www.cnblogs.com/ksy-c/p/12814857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!