简体   繁体   中英

Symfony2: Use different port for Rest API

I currently starting a (Symfony2) project where I have to use a different port for HTTP-Communication of the REST-API (JSON/XML) then the normal HTML-Content.

Is this possible? And what is the best practice? Can this be solved by (Symfony-) routing? Goal is to provide the REST-API just for "internal" use (traffic coming from an internal ethernet-connection) and to "block" traffic which comes from a external connection.

Additional info:

I add a route /api/user eg for the User Rest API and /api/projects for the Project Rest API.

Can I do something like?

<VirtualHost *:81>
    DocumentRoot /var/www/html/[Symfony-Folder]/web/api
</VirtualHost>

maybe you can try in your apache config to match your mydomain.tld/api route to a different port.

Also in your config file you can configure défault port like this :

# router configuration
router:
    ...
    http_port:            81

But I don't know if you can define a port for different routes but maybe you can take a look on the router configuration.

You can do something like this I think :

<VirtualHost *:80>
ServerName mydomain.tld/api

ProxyRequests Off
<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>
    ProxyPass / http://localhost:81/
    ProxyPassReverse / http://localhost:81/
</VirtualHost>

You listen on the port 80 but you redirect the traffic who match the /api path to a different port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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