15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > nginx 配置 虚拟主机

nginx 配置 虚拟主机

时间:2023-07-01 13:57:02 | 来源:网站运营

时间:2023-07-01 13:57:02 来源:网站运营

nginx 配置 虚拟主机:1.创建vhost文件夹,路径为/usr/local/nginx/conf/vhost

2.编辑nginx.conf,路径为 /usr/local/nginx/conf/nginx.conf
#修改一,引入虚拟主机的配置文件
#修改二,注释掉server段

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}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"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #修改一,引入虚拟主机的配置文件 include vhost/*.conf; #修改二,注释掉server段# server {# listen 80;# server_name www.jinggong.com;## #charset koi8-r;## #access_log logs/host.access.log main;## location / {# root /usr/local/nginx/html/jinggong/;# index index.php index.html index.htm;# try_files $uri $uri/ /index.php?$query_string;# }## #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;# #}## # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000# ## location ~ /.php$ {# root /usr/local/nginx/html/jinggong/;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# 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;# #}# } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}3.创建虚拟主机的配置文件,根据上文提到的以 *.conf 规则去创建文件名
#修改一,复制nginx.conf的server段为虚拟主机的配置文件
#修改二,修改虚拟主机的域名
#修改三,修改虚拟主机的访问路径

下文以 /usr/local/nginx/conf/vhost/test.jinggong.cn_80.conf 为例,进行讲解:

#修改一,复制nginx.conf的server段为虚拟主机的配置文件server { listen 80; #修改二,修改虚拟主机的域名 server_name test.jinggong.cn; #修改三,修改虚拟主机的访问路径 root /usr/local/nginx/html/jinggong/; #charset koi8-r; #access_log logs/host.access.log main; location / { #root /usr/local/nginx/html/jinggong/; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } #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; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ /.php$ { #root /usr/local/nginx/html/jinggong/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; 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; #} }4.至此一个虚拟主机的配置完成

关键词:主机,虚拟,配置

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭