首页 > 解决方案 > 哪个是在 ubuntu 16.04 中同时安装 Nginx 和 apache 的最佳方式

问题描述

我有一个 VPS 服务器并尝试安装ApacheNginx以在Ubuntu 16.04中协同工作,但使用不同的服务器名称和域。

所以,我有 apache 到端口 8000 和 nginx 到端口 8080。

Nginx 确实转到 8080 端口,因为使用NodeJs,这在路由https://localhost:8080/后面使用

Apache 使用 Laravel 5.5 和 PHP。

我已经配置到 Apache

/etc/apache2/sites-available/000.default.conf

<VirtualHost *:8000>
        ServerName www.myanotherdomainname.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/laravel/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/ect/apache2/ports.confListen 8000

对于 Nginx 中/etc/nginx/sites-available/default

location / {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80 default_server;
    listen [::]:80 default_server;
    server_name geckode.la www.mydomain.com;
    return 404; # managed by Certbot
}

www.mydomain.com中,NodeJs 运行的 script.js 运行良好

但是在www.myanotherdomainname.com中,返回404 Not Found nginx/1.10.3 (Ubuntu)

它甚至似乎都没有运行 apache

我需要知道使用 Nodejs 运行 apache 和 nginx 的最佳方式。

Apache状态和Nginx运行没有任何问题。

谢谢

标签: node.jslaravelapacheubuntunginx

解决方案


它只是按照你的吩咐去做。让我们运行一下您的配置:

if ($host = www.mydomain.com)- 没有...

if ($host = mydomain.com)- 还是不行...

return 404;- 好的,糟糕,我的意思是 HTTP/1.1 404 Not Found


推荐阅读