gpt4 book ai didi

nginx - nginx 上的服务器名称冲突

转载 作者:行者123 更新时间:2023-12-03 20:30:50 24 4
gpt4 key购买 nike

不知道为什么我得到 conflicting server name异常(exception)。

我接受请求 WWW在前缀与否。

return 301 https://$server_name$request_uri;是强制非 https 请求到 https。

知道如何解决这个异常吗?

配置文件

server {
listen 80 ;
server_name myApp.co www.myApp.co;

root /home/deployer/workspace/myApp-web/dist;
error_log /var/log/nginx/myApp_web_error.log warn;
access_log /var/log/nginx/myApp_web_access.log;
listen 443 ssl;
listen [::]:443 ssl;

ssl_certificate /etc/nginx/ssl/myApp_co.bundled.crt;
ssl_certificate_key /etc/nginx/ssl/myApp.key;
large_client_header_buffers 4 4800k;


location / {
try_files $uri $uri/ /index.html ; # make HTML5 workable
gzip on;
gzip_static on;
gzip_min_length 1k;
gzip_comp_level 6;
gzip_types application/javascript text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
}

location /api/v1 {
proxy_pass http://localhost:7617/api/v1/;
}
}

server {
listen 80;
server_name myApp.co www.myApp.co;
return 301 https://$server_name$request_uri;
}

异常日志
    2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored
2017/12/05 06:54:42 [warn] 6059#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored
2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored
2017/12/05 06:55:05 [warn] 6089#0: conflicting server name "www.myApp.co" on 0.0.0.0:80, ignored
2017/12/05 06:55:06 [warn] 6093#0: conflicting server name "myApp.co" on 0.0.0.0:80, ignored

最佳答案

诊断 :使用 sudo nginx -t查看警告或错误列表。

原因 :server_name myApp.co www.myApp.co;在默认的 NGINX 配置文件服务器块中,nginx.conf .

解决方案 : 离开 nginx.conf文件未受影响并编辑 /etc/nginx/conf.d/default.conf 内的服务器块(如果它不存在,请自行创建)改为您想要的服务器名称和配置。

看看this使您的服务器在 CentOS 上阻塞,您也可以在 Ubuntu 上搜索该标题。

这是默认的且未受影响的 nginx.conf文件:

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

}

关于nginx - nginx 上的服务器名称冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47843741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com