1、nginx 虛擬主機配置為什麼任意的二級域名都能訪問
nginx支持配置通配符域名
如果server_name中的名稱使用了通配符*,即可實現任意二級域名都可以訪問的效果
2、nginx https怎麼配置二級域名問題
請參考代碼,https如果監聽的是443埠,則網址後面不需要加埠;如果監聽的不是443埠則需要加埠。如下圖的 https://*.9yyule.com:8888
#user nobody;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 65535;
}
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;
# server_names_hash_bucket_size 128K;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 8m;
server_tokens off;
ignore_invalid_headers on;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
proxy_temp_path /usr/local/nginx-1.8/proxy_temp;
proxy_cache_path /usr/local/nginx-1.8/proxy_cache levels=1:2 keys_zone=cache_one:100m inactive=2d max_size=10g;
gzip on;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
server {
listen 80 default;
return 500;
server_tokens off;
root html; }
#server {
# listen 443 default;
# return 500;
# server_tokens off;
# root html; }
upstream name {
# server 116.31.118.114:8098 weight=2 fail_timeout=3s backup;
server 114.55.32.244:888 weight=1 max_fails=3 fail_timeout=300;
server 114.55.85.154:8080 weight=1 max_fails=3 fail_timeout=300;
ip_hash;
}
server {
listen 8888 default ;
server_name *.9yyule.com *.jiuyiyule.com *.yinqicai.com;
server_tokens off;
ssl on;
ssl_certificate /usr/local/nginx/conf/web.crt;
ssl_certificate_key /usr/local/nginx/conf/web.key;
error_page 497 https://$host:$server_port$request_uri;
location ~*/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://name;
proxy_http_version 1.1;
proxy_set_header Accept-Encoding "";
location ~ .*.(gif|jpg|png|html|css|js|ico|swf|pdf)(.*) {
proxy_pass http://name;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache cache_one;
add_header Nginx-Cache $upstream_cache_status;
proxy_cache_valid 200 304 301 302 24h;
proxy_cache_valid 404 1m;
proxy_cache_valid any 2d;
proxy_cache_key $host$uri$is_args$args;
expires 7d;
}
}
location ~ /purge(/.*)
{
auth_basic "TDT Center CACHE Center";
auth_basic_user_file /tmp/htpasswd;
allow 127.0.0.1;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
}
# error_page 404 /404.html;
# error_page 400 501 502 503 504 https://$host:$server_port$request_uri;
# location = /50x.html {
# root html;
# }
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
}
}
3、nginx 文件配置 如何設置域名
1.路徑: /etc/nginx/nginx.conf 和 /etc/nginx/conf.d,
其實只有/etc/nginx/nginx.conf 這一個配置文件,因為在nginx.conf中,其他配置文件都是可以利用 include 指令·引入的
部分配置文件:

server
{
listen 80;
server_name test.net;
root /var/www/test;#include none.conf;
#error_page 404 /404.html;
location ~ [^/].php(/|$)
{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
client_max_body_size 500m;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 12h;
}
#location = /HBLS.deb {
# rewrite . /HBLS.deb;
# default_type application/x-deb;
#}
access_log off;
#access_log logs/lung.access.log;
#error_log logs/lung.error.log debug;
}
4、Nginx如何配置二級域名
和頂級域名一樣的設置。只是把servername 改成你的二級域名就可以了
5、nginx如何綁定二級域名
nginx綁定二級域名是通過編輯配置文件中的server 的server_name來處理的。
如:
server {
listen 8001;
server_name domain_name;
#charset koi8-r;
#access_log logs/access.log main;
location / {
root html;
index index.html index.htm;
}
}
6、nginx內容頁重定向到二級域名
直接用Nginx的話理論可以,但是我不知道,不過可以給你提供另外一種解決方案,你可以試一下。在Nginx上配置PHP的一種方式不是可以講請求轉發給127.0.0.1:8080嘛,所以你可以在Nginx神申明一個虛擬主機,讓你一級域名的請求全部重定向給一個同一的PHP腳本,然後PHP腳本根據實際訪問的url修改後再讓客服端進行重定向到修改後的url。倒是肯定有更好的解決方法
7、請問Nginx下如何綁定泛域名
原理:一個nginx可以再配置文件中使用導出的變數。其中$host變數就是指的Y.XXX.com,因此直接使用$host變數就可以了。如下,就可以使用一個server把所有的請求指定到不同的目錄下。
實現方法:
http {
#...
server {
listen 80;
server_name $host;#在server_name中使用$host而不用自己去一個一個綁定了。
#...
location / {
#根目錄為$host,$PATH為$host所在的目錄。
root $PATH/$host;
#....
}
}