Nginx
所有虛擬主機重定向到一個主機 - nginx 反向代理
我有兩個用於 apache 和 nginx 的虛擬主機。域名是 (kevin-fechner.xyz & ketogenix.de)
我自己的網站 ( kevin-fechner.xyz ) 執行良好,而我只有一個域。但是在添加另一個之後,所有(只有兩個)重定向到新的(ketogenix.de)或報告 502 Bad Gateway。
兩個站點都在執行Wordpress。
環境:
- Ubuntu 16.04
- 阿帕奇/2.4.29
- nginx/1.10.3
- ssl
- http2
捲曲-I: ketogenix.de
HTTP/1.1 301 Moved Permanently Server: nginx/1.10.3 (Ubuntu) Date: Fri, 15 Jun 2018 08:39:48 GMT Content-Type: text/html Content-Length: 194 Connection: keep-alive Location: https://ketogenix.de/
kevin-fechner.xyz
HTTP/1.1 301 Moved Permanently Server: nginx/1.10.3 (Ubuntu) Date: Fri, 15 Jun 2018 08:39:58 GMT Content-Type: text/html Content-Length: 194 Connection: keep-alive Location: https://kevin-fechner.xyz/
https://downforeveryoneorjustme.com/
- 結果:它起來了
虛擬主機
ketogenix.de
nginx 伺服器{
root /var/www/ketogenix.de; index index.php index.html index.htm index.nginx-debian.html; server_name ketogenix.de www.ketogenix.de; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php; } location /wp-admin/ { index index.php; try_files $uri $uri/ /index.php$args; } location ~ \.php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; # proxy_pass http://127.0.0.1:8080; proxy_pass http://127.0.0.1:8080$request_uri; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/ketogenix.de/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/ketogenix.de/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = www.ketogenix.de) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = ketogenix.de) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name ketogenix.de www.ketogenix.de; return 301 https://ketogenix.de$request_uri; }
阿帕奇
<VirtualHost 127.0.0.1:8080> ServerAdmin developer.kevinfechner@gmail ServerName ketogenix.de ServerAlias www.ketogenix.de DocumentRoot /var/www/ketogenix.de <Directory /var/www/ketogenix.de/> Options Indexes FollowSymLinks AllowOverride all Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
kevin-fechner.xyz
nginx
server { root /var/www/kevin-fechner.xyz; index index.php index.html index.htm index.nginx-debian.html; server_name kevin-fechner.xyz www.kevin-fechner.xyz; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php; } location /wp-admin/ { index index.php; try_files $uri $uri/ /index.php$args; } location ~ \.php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host; # proxy_pass http://127.0.0.1:8080; # proxy_pass http://127.0.0.1:8080$request_uri; proxy_pass http://127.0.0.2:8081$request_uri; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } listen 443 ssl http2; # managed by Certbot ssl_certificate /etc/letsencrypt/live/kevin-fechner.xyz/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/kevin-fechner.xyz/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = kevin-fechner.xyz) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; listen [::]:80; server_name kevin-fechner.xyz www.kevin-fechner.xyz; return 301 https://kevin-fechner.xyz$request_uri; }
阿帕奇
<VirtualHost 127.0.0.2:8081> ServerAdmin developer.kevinfechner@gmail ServerName kevin-fechner.xyz ServerAlias www.kevin-fechner.xyz DocumentRoot /var/www/kevin-fechner.xyz <Directory /var/www/kevin-fechner.xyz/> Options Indexes FollowSymLinks AllowOverride all Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
錯誤日誌
什麼也沒說
我嘗試過的事情
- 添加伺服器名稱
- 更改 IP 地址
- 更改埠
- 重啟 nginx 和 apache
我希望你能幫助我。
注意:我已經從虛擬主機文件中刪除了我的所有評論。
看起來您沒有
Listen 127.0.0.2:8081
向 Apache 配置添加指令。這會導致 502 錯誤,因為沒有程序在偵聽埠 8081。