Home >Backend Development >PHP Tutorial >一个简单的nginx配置问题

一个简单的nginx配置问题

WBOY
WBOYOriginal
2016-06-06 20:38:31953browse

请问大家,访问api.com/v1时,想让请求都请求到/www/api/v1下面,应该怎么配置?
server_name后面加path路径的,不懂怎么配置,求指点

<code>server {
    listen 80;
    server_name api.com www.api.com;
    access_log /home/wwwlogs/access_nginx.log combined;
    index index.html index.php;

    location /v1/ {
        root /www/api/v1;
    }
</code>

回复内容:

请问大家,访问api.com/v1时,想让请求都请求到/www/api/v1下面,应该怎么配置?
server_name后面加path路径的,不懂怎么配置,求指点

<code>server {
    listen 80;
    server_name api.com www.api.com;
    access_log /home/wwwlogs/access_nginx.log combined;
    index index.html index.php;

    location /v1/ {
        root /www/api/v1;
    }
</code>

<code>location /v1/ {
    alias /www/api/v1/; # 结尾的 / 需要加上,不然路径解析会被翻译成  www.api.com/v1/v1
}
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn