不知道为什么我得到了 conflicting server name例外。
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;
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
您不能让两个服务器块侦听同一端口并使用相同的 server_name。
我认为在第一个服务器块中您正在尝试接受 https 请求,因此您必须将端口号更改为 443。
server {
listen 443;
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;
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30000 次 |
| 最近记录: |