nginx 配置文件里server_name为_是什么意思?

这个东西真不是很明白,别人都说这个是来反向代理的,可是怎么体现的,还有这个配置文件,是怎么样一个操作过程能讲下么,真的不明白,知道的非常零散,

Default server configuration

#
server {
listen 80 default_server;//这个是默认监听端口号 80 可是谁监听谁,nginx监听电脑上的80端口么
listen [::]:80 default_server;

# SSL configuration   
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;  //这个好像是我如果写一个静态网页可以在这个路径下写然后在环回地址显示,,具体是什么不明白求解释

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;//不明白 就是一堆html文件

server_name _;//也不明白  别人说配的域名 

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}//普通定位 但是也不明白 nginx去定位什么,

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # With php7.0-cgi alone:
    #fastcgi_pass 127.0.0.1:9000;
    # With php7.0-fpm:
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
} //正则匹配如果后缀是php网页就进行php解析么,

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny all;
#}

}
请稍微详细解释下,非常感谢大佬们啦,,,,,

人家问的是 server_name 值为 _ 下划线什么什么意思, 都瞎nm装逼。
谁知道回答一下,我也等着呢

变量 server_name _;
意味着 server_name 值为空,即匹配全部主机,比如我做一个全局 https 配置

server {
    listen 80 default;
    server_name _;
    if ($scheme = http) {
        return 301 https://$host$request_uri;
    }
    return 404;
}

这样不管使用什么域名,都能进行 http 重定向为 https 了

server_name 值为_,这里的 _   没有任何含义,你换成 __   _______也是一样的。

关键在于楼上   listen 80 default server  里面的default server,没有特殊设置匹配到的server_name的域名或ip,都匹配到default server这里。

先说nginx功能。

他是一个高性能http服务器,同时是一个反向代理服务器。

你现在这个配置文件前面只是http服务器功能。

listen 80 default_server; 是nginx监听当前端口。

root /var/www/html;是nginx的html文件位置。

location ~ .php$ { 这一段,是把php后缀的请求通过fastcgi传递到套接字里面了。这才是用到了他反向代理的一小部分。

他还支持配置多个fastcig的sock或者service。然后通过权重做负载均衡。

还可以直接用stream节点代理tcp端口,做端口转发。

更多内容,在nginx官网里都有,你什么时候用到了,什么时候去百度。这种工具我认为不太需要很认真的研究。

如果是虚拟主机,可以配置主机名,

server_name主要用于配置基于名称的虚拟主机(listen: 端口号 域名) 这里的域名你可以在windows中的host文件设置

nginx主要作用是反向代理和负载均衡,你这个问题属于反响代理的范畴。

server_name 是定义一个变量 ,写什么都行,最好见名知意。

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
这个地方会把所有/下面的请求代理到一个地方。需要自己配置代理的地点

设置ip和域名端口那些。多个用空格分开
图片说明

直接看: server_name localhost;

https://www.oschina.net/question/2913248_2196006
这个问题有人遇到过没