Nginx Configuration

The support of swoole_http_server for Http is not complete. So, you should configure your swoole server with nginx proxy in your production environment.

  1. map $http_upgrade $connection_upgrade {
  2. default upgrade;
  3. '' close;
  4. }
  5. server {
  6. listen 80;
  7. server_name your.domain.com;
  8. root /path/to/laravel/public;
  9. index index.php;
  10.  
  11. location = /index.php {
  12. # Ensure that there is no such file named "not_exists"
  13. # in your "public" directory.
  14. try_files /not_exists @swoole;
  15. }
  16. # any php files must not be accessed
  17. #location ~* \.php$ {
  18. # return 404;
  19. #}
  20. location / {
  21. try_files $uri $uri/ @swoole;
  22. }
  23.  
  24. location @swoole {
  25. set $suffix "";
  26.  
  27. if ($uri = /index.php) {
  28. set $suffix ?$query_string;
  29. }
  30.  
  31. proxy_set_header Host $http_host;
  32. proxy_set_header Scheme $scheme;
  33. proxy_set_header SERVER_PORT $server_port;
  34. proxy_set_header REMOTE_ADDR $remote_addr;
  35. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  36. proxy_set_header Upgrade $http_upgrade;
  37. proxy_set_header Connection $connection_upgrade;
  38.  
  39. # IF https
  40. # proxy_set_header HTTPS "on";
  41.  
  42. proxy_pass http://127.0.0.1:1215$suffix;
  43. }
  44. }