【问题标题】:Local nginx custom url本地 nginx 自定义 url
【发布时间】:2016-12-22 21:24:15
【问题描述】:

谁能帮我把这个 apache 文件转换成 nginx。我最喜欢的网站名称是“neptix”。所以在浏览器中,我可以访问类似的内容:neptix/about-us、neptix/contact-us。注意:没有 .com

<VirtualHost 127.0.0.1>
    ServerName neptix
    ServerAlias *.neptix

    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass /api http://52.35.118.165/api
    ProxyPassReverse /api http://52.35.118.165/api

    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/

    <Location /api>
        Order allow,deny
        Allow from all
    </Location>

    DirectoryIndex index.html index.php
</VirtualHost>

【问题讨论】:

  • 不清楚你问的是什么问题。
  • 我正在尝试使用 'sitename' 而不是 'sitename.com' 设置 ServerName/ServerAlias .. 所以在浏览器中我可以输入站点名称,然后它会转到 localhost:3000。如果我点击页面,则 url 将是 'sitename/about-us'
  • 您的浏览器需要知道输入“站点名称”时的去向,而这在 nginx 配置中无法做到。要在您自己的计算机上进行这项工作,您可以在主机文件中添加一个条目(Linux/OSX 上的 /etc/hosts,可能是 Windows 上的 C:\Windows\system32\drivers\etc\hosts),将站点名称映射到该文件的 ip服务器。您无法为每个人都这样做,因为您不能只定义自己的域。

标签: nginx


【解决方案1】:

这可能会有所帮助(它可能需要一些小的调整):

server {
    listen 80;
    server_name .neptix;
    index index.php index.html index.htm;

    location /api {
        proxy_pass http://52.35.118.165/api;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

【讨论】:

    猜你喜欢
    • 2011-12-15
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 2013-12-30
    • 2015-09-24
    • 2016-12-16
    • 2020-12-12
    • 1970-01-01
    相关资源
    最近更新 更多