情逸飞扬 發表於 2020-5-1 21:16:00

配置nginx域名

<p style="text-align: left">1 配置&nbsp;nginx.conf</p>
<p style="text-align: left">&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">server {
         listen       </span><span style="color: rgba(128, 0, 128, 1)">80</span><span style="color: rgba(0, 0, 0, 1)"> ;
       server_namewww.localhost.com;
      root         </span>/usr/share/nginx/<span style="color: rgba(0, 0, 0, 1)">html;
      index index.php index.html index.htm;
      charset utf</span>-<span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">;
      include </span>/etc/nginx/<span style="color: rgba(0, 0, 255, 1)">default</span>.d<span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">.conf;
      location / {
      }
    }</span></pre>
</div>
<p>2:配置<span style="font-family: &quot;Courier New&quot;; font-size: 12px">www.cmh.com项目&nbsp; conf.d/cmh.conf</span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">server {
      listen       </span><span style="color: rgba(128, 0, 128, 1)">80</span><span style="color: rgba(0, 0, 0, 1)">;
      server_name   www.cmh.com;
      charset utf</span>-<span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">;

      # Load configuration files </span><span style="color: rgba(0, 0, 255, 1)">for</span> the <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> server block.
      include </span>/etc/nginx/<span style="color: rgba(0, 0, 255, 1)">default</span>.d<span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">.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;
      }
    }</span></pre>
</div>
<p>3:配置php解析 default.d/php.conf</p>
<div class="cnblogs_code">
<pre>location ~<span style="color: rgba(0, 0, 0, 1)"> .php$ {
      try_files $uri </span>=<span style="color: rgba(128, 0, 128, 1)">404</span><span style="color: rgba(0, 0, 0, 1)">;
#      root </span>/usr/share/nginx/<span style="color: rgba(0, 0, 0, 1)">html;
      fastcgi_pass </span><span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span>:<span style="color: rgba(128, 0, 128, 1)">9000</span><span style="color: rgba(0, 0, 0, 1)">;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi.conf;
}

       error_page </span><span style="color: rgba(128, 0, 128, 1)">404</span> /<span style="color: rgba(128, 0, 128, 1)">404</span><span style="color: rgba(0, 0, 0, 1)">.html;
            location </span>= /<span style="color: rgba(0, 0, 0, 1)">40x.html {
      }

      error_page </span><span style="color: rgba(128, 0, 128, 1)">500</span> <span style="color: rgba(128, 0, 128, 1)">502</span> <span style="color: rgba(128, 0, 128, 1)">503</span> <span style="color: rgba(128, 0, 128, 1)">504</span> /<span style="color: rgba(0, 0, 0, 1)">50x.html;
            location </span>= /<span style="color: rgba(0, 0, 0, 1)">50x.html {
      }</span></pre>
</div>
<p>4 添加域名解析&nbsp; /etc/hosts</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span><span style="color: rgba(0, 0, 0, 1)">   localhost localhost.localdomain localhost4 localhost4.localdomain4www.localhost.com
::</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">         localhost localhost.localdomain localhost6 localhost6.localdomain6
</span><span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">33.10</span>    www.cmh.com</pre>
</div>
<p>&nbsp;</p>
<p>5 主机访问vagrant里域名</p>
<p>修改C:\Windows\System32\drivers\etc\hosts</p>
<p>添加&nbsp; </p>
<p>192.168.33.10 www.cmh.com</p>
<p>192.168.33.10 www.localhost.com</p>
<p>&nbsp;</p>
<p>user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;<br># Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;<br>events {&nbsp; &nbsp; worker_connections 1024;}<br>http {&nbsp; &nbsp; log_format&nbsp; main&nbsp; '$remote_addr - $remote_user [$time_local] "$request" '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '$status $body_bytes_sent "$http_referer" '&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '"$http_user_agent" "$http_x_forwarded_for"';<br>&nbsp; &nbsp; access_log&nbsp; /var/log/nginx/access.log&nbsp; main;<br>&nbsp; &nbsp; sendfile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;&nbsp; &nbsp; tcp_nopush&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;&nbsp; &nbsp; tcp_nodelay&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;on;&nbsp; &nbsp; keepalive_timeout&nbsp; &nbsp;65;&nbsp; &nbsp; types_hash_max_size 2048;<br><br>&nbsp; &nbsp; include&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/etc/nginx/mime.types;&nbsp; &nbsp; default_type&nbsp; &nbsp; &nbsp; &nbsp; application/octet-stream;<br>&nbsp; &nbsp; # Load modular configuration files from the /etc/nginx/conf.d directory.&nbsp; &nbsp; # See http://nginx.org/en/docs/ngx_core_module.html#include&nbsp; &nbsp; # for more information.&nbsp; &nbsp; include /etc/nginx/conf.d/*.conf;<br>&nbsp; &nbsp; server {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listen&nbsp; &nbsp; &nbsp; &nbsp;80 ;#&nbsp; &nbsp; &nbsp; &nbsp; listen&nbsp; &nbsp; &nbsp; &nbsp;80 default_server;#&nbsp; &nbsp; &nbsp; &nbsp; listen&nbsp; &nbsp; &nbsp; &nbsp;[::]:80 default_server;#&nbsp; &nbsp; &nbsp; &nbsp; server_name&nbsp; _;&nbsp; &nbsp; &nbsp; &nbsp;server_name&nbsp; www.localhost.com;&nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/usr/share/nginx/html;&nbsp; &nbsp; &nbsp; &nbsp; index index.php index.html index.htm;&nbsp; &nbsp; &nbsp; &nbsp; charset utf-8;<br>&nbsp; &nbsp; &nbsp; &nbsp; # Load configuration files for the default server block.&nbsp; &nbsp; &nbsp; &nbsp; include /etc/nginx/default.d/*.conf;<br>&nbsp; &nbsp; &nbsp; &nbsp; location / {&nbsp; &nbsp; &nbsp; &nbsp; }<br>#&nbsp; &nbsp; &nbsp; &nbsp; error_page 404 /404.html;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; location = /40x.html {#&nbsp; &nbsp; &nbsp; &nbsp; }<br>#&nbsp; &nbsp; &nbsp; &nbsp; error_page 500 502 503 504 /50x.html;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; location = /50x.html {#&nbsp; &nbsp; &nbsp; &nbsp; }<br>#&nbsp; &nbsp; &nbsp; &nbsp;location ~ .php$ {#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try_files $uri =404;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root /usr/share/nginx/html;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass 127.0.0.1:9000;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_index index.php;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include fastcgi.conf;#&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/ksy-c/p/12814857.html
頁: [1]
查看完整版本: 配置nginx域名