Nginx PHP多站点配置

正文开始

<p>1、在 /etc/nginx 下创建 vhosts 目录<br /></p><p>2、在 /etc/nginx/vhosts/ 里创建一个名字为example1.conf 的文件,把以下内容拷进去<br /></p><p> 代码如下:</p><p></p><pre>server { listen 80; server_name example1.com linux2.example1.com; access_log logs/access_linux.example1.log main; location / { root /etc/nginx/www/web_folder; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ /.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /etc/nginx/www/web_folder/$fastcgi_script_name; include fastcgi_params; } location ~ //.ht { deny all; } }</pre> <br /><p></p><p>打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上文件包含进来</p><p></p><pre>user nginx; worker_processes 1; # main server error log error_log /var/log/nginx/error.log ; pid /var/run/nginx.pid; events { worker_connections 1024; } # main server config http { include 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"'; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 80; server_name _; access_log /var/log/nginx/access.log main; server_name_in_redirect off; location / { root /usr/share/nginx/html; index index.html; } } # 包含所有的虚拟主机的配置文件 include /etc/nginx/vhosts/*; }</pre> 重启 Nginx<br /><p></p><p></p><p>需要先执行</p><p>nginx -c /etc/nginx/nginx.conf</p>重新加载 并重启 <br /><p>nginx -t && nginx -s reload<br /></p><p><br /></p><p><br /></p><p>LNMP新版</p><p></p><pre>     server {         listen 80;     root  /alidata/www/linux_pifa;         index  index.html index.htm index.php;         server_name  linux.pifayanjing.com;         #charset koi8-r;         #access_log  logs/host.access.log  main;     access_log  /alidata/logs/access_linux.pifayanjing.log  access;                 #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   html;         }         # proxy the PHP scripts to Apache listening on 127.0.0.1:80         #         #location ~ .php$ {         #    proxy_pass   http://127.0.0.1:80;         #}         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000         #         location ~ .php$ {             root           /alidata/www/linux_pifa;             fastcgi_pass   127.0.0.1:9000;             fastcgi_index  index.php;             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;             include        fastcgi_params;         }         # deny access to .htaccess files, if Apache's document root         # concurs with nginx's one         #         location ~ /.ht {             deny  all;         }     } </pre> <br /><p></p><p><br /></p><p><br /></p>

正文结束

阿里云、腾讯云 apache的vhost配置https 阿里云centos 挂载新磁盘