简体   繁体   English

Nodejs 应用程序部署在 CentOS 7 中,Apache 无法被域访问

[英]Nodejs app deployed in CentOS 7 with Apache not accessible by domain

I'm trying to deploy my app in CentOS 7 with Apache but even though the app is running, it is not accessible neither by the domain.我正在尝试使用 Apache 在 CentOS 7 中部署我的应用程序,但即使应用程序正在运行,域也无法访问它。

When I try to visit with the domain, it says Forbidden You don't have permission to access this resource .当我尝试访问该域时,它显示Forbidden You don't have permission to access this resource

Please note that I can access the website with ip:port.请注意,我可以使用 ip:port 访问该网站。

This is the configuration for Apache in sites-available directory with file name example.com.conf :这是sites-available目录中 Apache 的配置,文件名为example.com.conf

<VirtualHost *:80>
        ServerName  example.com
        ProxyRequests On
        ProxyPass / http://server-ip:3000
        ProxyPassReverse / http://server-ip:3000
</VirtualHost>

I also added IncludeOptional sites-enabled/*.conf inside httpd.conf file.我还在httpd.conf文件中添加了IncludeOptional sites-enabled/*.conf

I'm not used to CentOS 7 and neither with Apache so I don't know what I'm doing wrong here.我不习惯 CentOS 7 也不习惯 Apache 所以我不知道我在这里做错了什么。 Also note that the domain is configured with CloudFlare and I think the domain has SSL installed as I can see in the browser, it doesn't say 'Not Secure'.另请注意,该域配置了 CloudFlare,我认为该域安装了 SSL,正如我在浏览器中看到的那样,它没有说“不安全”。 It is also worth mentioning that the server host is Private Cloud Server with DirectAdmin.还值得一提的是,服务器主机是带有 DirectAdmin 的私有云服务器。

If think you need to change from ip-address to localhost如果认为您需要从 ip-address 更改为 localhost

Here is a full example of apache virtualhost with SSL:这是 apache 虚拟主机与 SSL 的完整示例:

<VirtualHost xxx.example.com:80>
        RewriteEngine on
        RewriteCond %{SERVER_PORT} ^80$
        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</VirtualHost>

<VirtualHost *:443>
        Header always set Strict-Transport-Security "max-age=31536000"

        ServerName xxx.example.com

        SetOutputFilter DEFLATE
        SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$"no-gzip
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

        ExpiresActive On
        ProxyRequests off
        RequestHeader add original-protocol-ssl 1
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
        <Location />
                ProxyPass http://localhost:3511/
                ProxyPassReverse http://localhost:3511/
                ProxyPreserveHost On
        </Location>
        SSLCertificateFile /etc/letsencrypt/live/xxx.example.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/xxx.example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /etc/letsencrypt/live/xxx.example.com/chain.pem
</VirtualHost>

You can naturally remove all ssl configuration.您可以自然删除所有 ssl 配置。

Also, don't leave ProxyRequest to On because open proxy may be dangerous if not secured: https://httpd.apache.org/docs/2.4/fr/mod/mod_proxy.html#proxyrequests另外,不要将 ProxyRequest 保留为 On,因为如果不保护开放代理可能会很危险: https://httpd.apache.org/docs/2.4/fr/mod/mod_proxy.html#proxyrequests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM