【问题标题】:how to convert nginx config file from code-server to apache2 config file如何将 nginx 配置文件从代码服务器转换为 apache2 配置文件
【发布时间】:2021-12-19 21:40:00
【问题描述】:

我来到这里,因为正如标题所示,我安装了代码服务器,除了我希望它在 apache2 下而不是在 nginx 下。我正在尝试在 https 下设置我的服务器,我已经有了我的证书,我只需要配置文件。 我是初学者,所以我不了解有关 nginx 和代码服务器如何工作以及如何适应它的一切。我遵循了许多教程来执行此操作,并且配置文件始终相同:

server {
    listen 80;
    listen [::]:80;
    server_name domainname.domain.dev;
    location / {
        proxy_pass http://localhost:8080/;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
    }
}

在我不得不设置服务文件之前:code-server.service:

[Unit]
Description=code-server
After=apache2.service #I changed this line before it was: nginx.service

[Service]
Type=simple
Environment=PASSWORD=code-server-password
ExecStart=/usr/bin/code-server --bind-addr 127.0.0.1:8080 --user-data-dir /var/lib/code-server --auth password
Restart=always

[Install]
WantedBy=multi-user.target

你能帮帮我吗?我正在尝试找到解决此问题的方法,但我不知道该怎么做

【问题讨论】:

    标签: apache nginx https apache2 code-server


    【解决方案1】:

    我相信以下应该有效:

    <VirtualHost _default_:80>
    ServerName myserverdomainname
    ServerAdmin webmaster@myserverdomainname
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    RequestHeader set Connection ""
    RequestHeader set Upgrade $http_upgrade;
    RequestHeader set Connection "upgrade"
    RequestHeader set X-Forwarded-Proto "http"
    <Location />
    </VirtualHost>
    

    启用 SSL

    <VirtualHost _default_:443>
    ServerName myserverdomainname
    ServerAdmin webmaster@myserverdomainname
    SSLEngine on
    SSLProxyEngine on
    ##LE Certs
    SSLCertificateFile /etc/letsencrypt/live/domain/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/domain/fullchain.pem
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8000/
    ProxyPassReverse / http://localhost:8000/
    RequestHeader set Connection ""
    RequestHeader set Upgrade $http_upgrade;
    RequestHeader set Connection "upgrade"
    RequestHeader set X-Forwarded-Proto "https"
    <Location />
    </VirtualHost>
    

    【讨论】:

    • 非常感谢您的回答,我应该将 http 和 https 的虚拟主机放在同一个文件中吗?你用 关闭了 标记它不是 正常吗?
    • 您可以同时使用两者,但是,如果您的站点配置为将 http 重定向到 https,则只需要 https 虚拟主机。同时使用 关闭虚拟主机
    【解决方案2】:

    所以最后我找到了解决问题的方法,我不得不使用 apache 反向代理。我不明白所有的代码,但它的工作原理。对于那些和我有同样问题的人,我找到了这个网站:https://toscode.gitee.com/crazyleega/code-server/blob/master/doc/quickstart.md

    为了激活 https 从而激活 ssl,我这样做了:

    <VirtualHost *:443>
      ServerName domainname
    
      RewriteEngine On
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
      RewriteRule /(.*)           http://localhost:8080/$1 [P,L]
      SSLEngine on
      SSLProxyEngine on
      SSLCertificateFile pathofyourcert
      SSLCertificateKeyFile pathofyourkey
      ProxyRequests off
      ProxyPass        / http://localhost:8080/ nocanon
      ProxyPassReverse / http://localhost:8080/
    </VirtualHost>

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 2010-11-19
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      相关资源
      最近更新 更多