配置nginx域名
<p style="text-align: left">1 配置 nginx.conf</p><p style="text-align: left"> </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: "Courier New"; font-size: 12px">www.cmh.com项目 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 添加域名解析 /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> </p>
<p>5 主机访问vagrant里域名</p>
<p>修改C:\Windows\System32\drivers\etc\hosts</p>
<p>添加 </p>
<p>192.168.33.10 www.cmh.com</p>
<p>192.168.33.10 www.localhost.com</p>
<p> </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 { worker_connections 1024;}<br>http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';<br> access_log /var/log/nginx/access.log main;<br> sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048;<br><br> include /etc/nginx/mime.types; default_type application/octet-stream;<br> # 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;<br> 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;<br> # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf;<br> location / { }<br># error_page 404 /404.html;# location = /40x.html {# }<br># error_page 500 502 503 504 /50x.html;# location = /50x.html {# }<br># 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;# }<br> }</p>
<p> </p><br><br>
来源:https://www.cnblogs.com/ksy-c/p/12814857.html
頁:
[1]