Nginx 配置多站点vhost 的方法

前端之家收集整理的这篇文章主要介绍了Nginx 配置多站点vhost 的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

假设你想在Linux Nginx中用不同的域名访问不同的目录,这时就要配置多个vhost,具体配置如下,假设网站根目录设定在/var/www/

1、在/var/www/下新建两个目录

2、编辑/etc/Nginx/Nginx.conf

Nginx/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 /var/log/Nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/Nginx/conf.d/*.conf;   #主要是加入此行,如有则忽略 }

3、在/etc/Nginx/conf.d下新建两个conf文件

Nginx/conf.d/ushark.net.conf /etc/Nginx/conf.d/ushark.wang.conf

4、复制如下配置信息到两个文件中,只要修改红色部分内容  !!! server_name与root保持一致即目录和域名一一对应 !!!

Nginx/host.access.log main; root /var/www/ushark.net/; if (!-e $request_filename){   # rewrite可根据网站需要增删 rewrite ^/(.*) /index.PHP last; } location / { index index.PHP index.html index.htm; } #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 /var/www/ushark.net/; } # 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$ { fastcgi_index index.PHP; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } # deny access to .htaccess files,if Apache's document root # concurs with Nginx's one # #location ~ /\.ht { # deny all; #} }

5、重启Nginx

Nginx

6、 编辑/etc/hosts  !!! 核心步骤 !!!

总结

以上所述是小编给大家介绍的Nginx 配置多站点vhost 的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

猜你在找的JavaScript相关文章