标签: apache2

如何在ubuntu上为django restful服务配置apache2

我的 ubuntu 服务器上有 django restful 服务,它们在端口 84 上运行。

当请求被发送时,它来自运行在端口 80 上的 apache2 服务器。

现在假设我的服务器 ip 是“xx.xx.xx.10”,当我用这个 url http://xx.xx.xx.10/user调用时,用户是在端口 84 上的 django rest 框架上运行的其余服务.然后请求应该通过apache2进入我的django rest服务并返回所需的输出。

我尝试在 apache2 中使用以下配置:-

    <VirtualHost *:80>
     WSGIScriptAlias / /myproject/myapp/test/wsgi.py
     <Directory "/myproject/myapp/test/">        
      <Files "wsgi.py">
        Require all granted
      </Files>
     </Directory>
    </VirtualHost>
Run Code Online (Sandbox Code Playgroud)

但这给出了内部错误,说 test.settings 不存在。

这是配置在apache服务器上不同端口上运行的restful服务的正确方法吗?

apache django apache2 django-rest-framework

5
推荐指数
1
解决办法
697
查看次数

如何配置docker文件像perl一样运行cgi-script

我有这个文件:

  • 索引.php
  • 文件
  • /conf/myawesomesite.conf
  • cgi-bin/helloworld.pl

在 /conf/myawesomesite.conf 中:

<VirtualHost *:80>

    ServerAdmin webmaster@myawesomesite.com
    ServerName myawesomesite.com
    ServerAlias www.myawesomesite.com
    DocumentRoot /var/www/html/myawesomesite.com/httpdocs
    ErrorLog /var/www/myawesomesite.com/logs/error.log 
    CustomLog /var/www/myawesomesite.com/logs/access.log combined
    Options ExecCGI
    AddHandler cgi-script .pl

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

在 Dockerfile 中:

FROM ubuntu:16.04

## Install Base Packages
RUN apt-get update && apt-get -y install \
    apache2 \
    make \
    curl \
    git \
    gcc

RUN a2enmod rewrite

## Install Perl
RUN apt-get update && apt-get -y install \
    libapache2-mod-perl2 \
    perl

RUN a2enmod perl

## Install PHP
RUN apt-get …
Run Code Online (Sandbox Code Playgroud)

perl apache2 docker

5
推荐指数
1
解决办法
5801
查看次数

Apache mod-x-sendfile 但用于远程 url

我正在编写一个 PHP 应用程序,用户可以在其中下载一些文件。并非所有文件都可以被所有用户下载,一些复杂的权限检查正在幕后进行。

由于此权限检查,我不想公开文件实际所在的 url,因为我想强制用户始终使用验证其凭据的端点。

在我当前的实现中,这都是使用 PHP(fread 等)编写的。为了最大限度地减少内存消耗,它被实现为一个流,这样 PHP 主要充当代理。

但我想只使用 PHP 进行身份验证,然后使用 Apache2 进行实际托管。环顾四周,似乎 X-Sendfile 是一个理想的选择。

使用 X-Sendfile 的唯一问题是它仅适用于本地文件,而我的文件位于远程存储服务器(而不是我的网络服务器)上。

所以基本上我有一个直接链接到我的存储服务器(我想隐藏):

https://storage.example.com/the-pet-goat.pdf

以及用户与之交互的公共链接:

https://www.example.com/randomized-id/download

我希望当用户访问https://www.example.com/randomized-id/download 时检查其凭据,如果成功,他应该(不可见地)重定向到存储服务器上的文件。

有没有办法实现这一点(使用Apache)?我找到了 X-Accel-Redirect,但那是针对 NGinx 的

我在 SO 上发现了一个类似的问题: Alternative to X-sendfile in Apache for sent file given a URL? 但那个是专门针对 S3、Apache(和 Ruby on Rails)的,而这个问题对于 Apache 来说更通用。

php apache2 x-sendfile

5
推荐指数
0
解决办法
630
查看次数

WebSocket 握手:意外响应代码:400

找不到解决办法。我不太喜欢 apache 配置,但我目前需要它来重新路由到本地服务器。我正在使用在 Internet 某处找到的重新路由的解决方案。有效。我有一个连接,但我收到此错误。WebSocket 握手:意外响应代码:400

代码:

<Location /tools/>
        RewriteEngine On

        RewriteCond %{REQUEST_URI}  ^/tools/socket.io            [NC]
        RewriteCond %{QUERY_STRING} transport=websocket          [NC]
        RewriteRule "^/tools/socket.io"           "ws://localhost:8080/socket.io/" [P,L]

        ProxyPass http://localhost:8080/
        ProxyPassReverse http://localhost:8080/
</Location>
Run Code Online (Sandbox Code Playgroud)

apache2 websocket

5
推荐指数
1
解决办法
2962
查看次数

安装 LetsEncrypt ssl 证书时出现“无法安装证书”错误

我正在尝试安装 Lets Encrypt,但没有成功。我收到以下错误:

Keeping the existing certificate
Could not reverse map the HTTPS VirtualHost to the original

IMPORTANT NOTES:

Unable to install the certificate
Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/www.deals4u.co.il/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/www.deals4u.co.il/privkey.pem Your cert will expire on 2018-05-19. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew all of your certificates, run "certbot renew"
Run Code Online (Sandbox Code Playgroud)

我的 …

ubuntu ssl apache2 lets-encrypt

5
推荐指数
0
解决办法
1764
查看次数

Tomcat 和 Apache2 上使用 Spring 启动的 CORS OPTIONS 请求

我正在尝试在我的 Spring 启动应用程序上配置 CORS。我将 CrossOrigin 注释添加到我的控制器类中。

@CrossOrigin
@RestController
@RequestMapping("api/user")
public class UserApiController {
    ...
}
Run Code Online (Sandbox Code Playgroud)

当我在我的本地机器上运行它时,我得到了这些 OPTIONS 请求的响应头:

Access-Control-Allow-Credentials ?true
Access-Control-Allow-Methods ?GET
Access-Control-Allow-Origin ?http://www.test.be
Access-Control-Max-Age ?1800
Allow ?GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Cache-Control ?no-cache, no-store, max-age=0, must-revalidate
Content-Length ?0
Date ?Wed, 28 Mar 2018 09:13:33 GMT
Expires ?0
Pragma ?no-cache
Vary ?Origin
X-Content-Type-Options ?nosniff
X-Frame-Options ?DENY
X-XSS-Protection ?1; mode=block
Run Code Online (Sandbox Code Playgroud)

我在 Tomcat 服务器上部署了这个应用程序,在 Linux 上运行的 Apache2 服务器后面。当我在那里做同样的请求时,我得到了这个:

Allow ?GET,HEAD
Cache-Control ?no-cache, no-store, max-age=0, must-revalidate
Connection ?Keep-Alive
Date ?Wed, …
Run Code Online (Sandbox Code Playgroud)

java apache2 cors spring-boot tomcat9

5
推荐指数
0
解决办法
678
查看次数

PHP 7.2:没有解析额外的 .ini 文件

我有一个 ubuntu 服务器(16.04.4 LTS),apache2 运行 php7.0(Apache 2.0 Handler)和 php7.2(FPM/FastCGI)。

PHP7.2 工作正常,除了没有加载扩展 - 像 json 或其他任何东西。查看我的 phpinfo():

System  Linux srvindkdif 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64
Build Date  Jun 22 2018 08:44:50
Server API  FPM/FastCGI
Virtual Directory Support   disabled
Configuration File (php.ini) Path   /etc/php/7.2/fpm
Loaded Configuration File   /etc/php/7.2/fpm/php.ini
Scan this dir for additional .ini files /etc/php/7.2/fpm/conf.d
Additional .ini files parsed    (none)
PHP API 20170718
PHP Extension   20170718
Zend Extension  320170718
Zend Extension Build    API320170718,NTS
PHP Extension Build …
Run Code Online (Sandbox Code Playgroud)

php apache2 ubuntu-16.04 php-7.2

5
推荐指数
1
解决办法
4175
查看次数

使用 HTTPS 在 Apache 后面配置 Tomcat8

我在我的服务器中的 8080 端口安装了 Tomcat 8,我用安全的 Apache(使用 Proxy Pass)公开了它。

这是我的 Apache 配置:

<VirtualHost *:443>
    ServerName myserver.com

    ProxyRequests Off
    ProxyPreserveHost On

    ProxyPass           /odata/    http://172.31.36.251:8080/
    ProxyPassReverse    /odata/    http://172.31.36.251:8080/

    <Proxy *>
        allow from all
    </Proxy>

    RequestHeader set X-Forwarded-Port 443
    RequestHeader set X-Forwarded-Scheme https
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

这里是Tomcat server.xml 配置

<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" 
            address="172.31.36.251" 
            proxyName="myserver.com" 
            scheme="https" proxyPort="443"  />
Run Code Online (Sandbox Code Playgroud)

一切正常,直到这里。如果我调用我的应用程序:https : //myserver.com/odata/D3a1593adae89/odata.svc/

我得到:

<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="https://myserver.com:443/D3a1593adae89/odata.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="Maintables">
<atom:title>Maintables</atom:title>
</collection>
</workspace>
</service>
Run Code Online (Sandbox Code Playgroud)

问题: 如果在结果中看到属性xml:base,Tomcat用端口装饰地址,我真的不知道如何删除它。地址也是错误的:它应该是https://myserver.com:443/ odata /D3a1593adae89/odata.svc/ 。我一直在环顾四周,尝试将proxyPort设置为空白但什么也没有。我认为这与使用反向代理时断开的链接有关,如 …

https apache2 proxypass tomcat8

5
推荐指数
1
解决办法
483
查看次数

无法在 ubuntu 18.04 上启动 Apache HTTP 服务器

我试图在我的 ubuntu 18.04 上创建一个 Web 服务器,所以我安装了 Apache2,但我无法启动它。这是我运行systemctl status apache2.service命令时出现的内容

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           ??apache2-systemd.conf
   Active: failed (Result: exit-code) since Sat 2020-02-22 13:58:09 CET; 34s ago
  Process: 2791 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Run Code Online (Sandbox Code Playgroud)
Feb 22 13:58:09 moemen apachectl[2791]: AH00558: apache2: Could not reliably determine the server's
Feb 22 13:58:09 moemen apachectl[2791]: (98)Address already in use: AH00072: make_sock: could not b
Feb 22 13:58:09 moemen apachectl[2791]: (98)Address already in use: …
Run Code Online (Sandbox Code Playgroud)

apache ubuntu apache2

5
推荐指数
2
解决办法
4万
查看次数

Big Sur MacOS Vagrant 问题

我刚刚将 MacOS 更新为新版本(Big Sur)。当我尝试 vagrant up 启动 vagrant 时,它显示如下错误:

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" …
Run Code Online (Sandbox Code Playgroud)

apache2 vagrant

5
推荐指数
1
解决办法
2626
查看次数