# Socket.io
location /socket.io/ {
  proxy_pass https://localhost:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
  proxy_set_header Host $host;
  proxy_read_timeout 86400s;
}

# Rewrite Rules
location / {
  if (-f $request_filename) {
    break;
  }
  if (-d $request_filename){
    break;
  }
  rewrite ^/apis/php/(.*)$ /apis/php/index.php?$args last;
  rewrite ^/install/?$ /install.php last;
  rewrite ^/signin/?$ /modules/sign.php?do=in last;
  rewrite ^/signup/?$ /modules/sign.php?do=up last;
  rewrite ^/signout/?$ /modules/sign.php?do=out last;
  rewrite ^/reset/?$ /modules/sign.php?do=reset last;
  rewrite ^/activation/([^/]+)/?$ /modules/activation.php?code=$1 last;
  rewrite ^/connect/([^/]+)/?$ /modules/connect.php?do=connect&provider=$1 last;
  rewrite ^/revoke/([^/]+)/?$ /modules/connect.php?do=revoke&provider=$1 last;
  rewrite ^/started/?$ /modules/started.php last;
  rewrite ^/started/finished?$ /modules/started.php?finished=true last;
  rewrite ^/static/([^/]+)/?$ /modules/static.php?url=$1 last;
  rewrite ^/contacts/?$ /modules/contact.php last;
  rewrite ^/support/?$ /support.php last;
  rewrite ^/support/tickets/?$ /support.php?view=tickets last;
  rewrite ^/support/tickets/new/?$ /support.php?view=new last;
  rewrite ^/support/tickets/find/?$ /support.php?view=find last;
  rewrite ^/support/tickets/([^/]+)/?$ /support.php?view=ticket&ticket_id=$1 last;
  rewrite ^/directory/?$ /directory.php last;
  rewrite ^/directory/([^/]+)/?$ /directory.php?view=$1 last;
  rewrite ^/directory/([^/]+)/([^/]+)/?$ /directory.php?view=$1&page=$2 last;
  rewrite ^/search/?$ /search.php last;
  rewrite ^/search/hashtag/([^/]+)/?$ /search.php?query=$1&hashtag=1 last;
  rewrite ^/search/hashtag/([^/]+)/([^/]+)/?$ /search.php?query=$1&tab=$2&hashtag=1 last;
  rewrite ^/search/([^/]+)/?$ /search.php?query=$1&hashtag=0 last;
  rewrite ^/search/([^/]+)/([^/]+)/?$ /search.php?query=$1&tab=$2&hashtag=0 last;
  rewrite ^/packages/?$ /packages.php?view=packages last;
  rewrite ^/upgraded/?$ /packages.php?view=upgraded last;
  rewrite ^/messages/?$ /messages.php last;
  rewrite ^/messages/new?$ /messages.php?view=new last;
  rewrite ^/messages/([^/]+)/?$ /messages.php?cid=$1 last;
  rewrite ^/notifications/?$ /notifications.php last;
  rewrite ^/payment_status/([^/]+)/?$ /payment_status.php?view=$1 last;
  rewrite ^/settings/?$ /settings.php last;
  rewrite ^/settings/([^/]+)/?$ /settings.php?view=$1 last;
  rewrite ^/settings/([^/]+)/([^/]+)/?$ /settings.php?view=$1&sub_view=$2 last;
  rewrite ^/live/?$ /live.php last;
  rewrite ^/posts/([^/]+)/?$ /post.php?post_id=$1 last;
  rewrite ^/photos/([^/]+)/?$ /photo.php?photo_id=$1 last;
  rewrite ^/popular/?$ /index.php?view=popular last;
  rewrite ^/discover/?$ /index.php?view=discover last;
  rewrite ^/saved/?$ /index.php?view=saved last;
  rewrite ^/scheduled/?$ /index.php?view=scheduled last;
  rewrite ^/memories/?$ /index.php?view=memories last;
  rewrite ^/watch/?$ /watch.php last;
  rewrite ^/watch/category/([^/]+)/?$ /watch.php?view=category&category_id=$1 last;
  rewrite ^/watch/category/([^/]+)/([^/]+)/?$ /watch.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/watch/category/([^/]+)/([^/]+)/([^/]+)/?$ /watch.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/ads/?$ /ads.php last;
  rewrite ^/ads/new?$ /ads.php?view=new last;
  rewrite ^/ads/edit/([^/]+)/?$ /ads.php?view=edit&campaign_id=$1 last;
  rewrite ^/wallet/?$ /wallet.php last;
  rewrite ^/wallet/payments/?$ /wallet.php?view=payments last;
  rewrite ^/boosted/posts/?$ /index.php?view=boosted_posts last;
  rewrite ^/boosted/pages/?$ /index.php?view=boosted_pages last;
  rewrite ^/boosted/groups/?$ /index.php?view=boosted_groups last;
  rewrite ^/boosted/events/?$ /index.php?view=boosted_events last;
  rewrite ^/people/?$ /people.php last;
  rewrite ^/people/find/?$ /people.php?view=find last;
  rewrite ^/people/friend_requests/?$ /people.php?view=friend_requests last;
  rewrite ^/people/sent_requests/?$ /people.php?view=sent_requests last;
  rewrite ^/pages/?$ /pages.php last;
  rewrite ^/pages/liked/?$ /pages.php?view=liked last;
  rewrite ^/pages/manage/?$ /pages.php?view=manage last;
  rewrite ^/pages/category/([^/]+)/?$ /pages.php?view=category&category_id=$1 last;
  rewrite ^/pages/category/([^/]+)/([^/]+)/?$ /pages.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/pages/category/([^/]+)/([^/]+)/([^/]+)/?$ /pages.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/pages/([^/]+)/?$ /page.php?username=$1 last;
  rewrite ^/pages/([^/]+)/([^/]+)/?$ /page.php?username=$1&view=$2 last;
  rewrite ^/pages/([^/]+)/([^/]+)/([^/]+)/?$ /page.php?username=$1&view=$2&id=$3 last;
  rewrite ^/groups/?$ /groups.php last;
  rewrite ^/groups/joined/?$ /groups.php?view=joined last;
  rewrite ^/groups/manage/?$ /groups.php?view=manage last;
  rewrite ^/groups/category/([^/]+)/?$ /groups.php?view=category&category_id=$1 last;
  rewrite ^/groups/category/([^/]+)/([^/]+)/?$ /groups.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/groups/category/([^/]+)/([^/]+)/([^/]+)/?$ /groups.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/groups/([^/]+)/?$ /group.php?username=$1 last;
  rewrite ^/groups/([^/]+)/([^/]+)/?$ /group.php?username=$1&view=$2 last;
  rewrite ^/groups/([^/]+)/([^/]+)/([^/]+)/?$ /group.php?username=$1&view=$2&id=$3 last;
  rewrite ^/events/?$ /events.php last;
  rewrite ^/events/going/?$ /events.php?view=going last;
  rewrite ^/events/interested/?$ /events.php?view=interested last;
  rewrite ^/events/invited/?$ /events.php?view=invited last;
  rewrite ^/events/manage/?$ /events.php?view=manage last;
  rewrite ^/events/category/([^/]+)/?$ /events.php?view=category&category_id=$1 last;
  rewrite ^/events/category/([^/]+)/([^/]+)/?$ /events.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/events/category/([^/]+)/([^/]+)/([^/]+)/?$ /events.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/events/([^/]+)/?$ /event.php?event_id=$1 last;
  rewrite ^/events/([^/]+)/([^/]+)/?$ /event.php?event_id=$1&view=$2 last;
  rewrite ^/events/([^/]+)/([^/]+)/([^/]+)/?$ /event.php?event_id=$1&view=$2&id=$3 last;
  rewrite ^/reels/?$ /reels.php last;
  rewrite ^/reels/([^/]+)/?$ /reels.php?view=reel&post_id=$1 last;
  rewrite ^/my/blogs/?$ /index.php?view=blogs last;
  rewrite ^/blogs/?$ /blogs.php last;
  rewrite ^/blogs/new/?$ /blogs.php?view=new last;
  rewrite ^/blogs/edit/([^/]+)/?$ /blogs.php?view=edit&post_id=$1 last;
  rewrite ^/blogs/category/([^/]+)/([^/]+)/?$ /blogs.php?view=category&category_id=$1 last;
  rewrite ^/blogs/([^/]+)/([^/]+)/?$ /blogs.php?view=blog&post_id=$1 last;
  rewrite ^/my/products/?$ /index.php?view=products last;
  rewrite ^/market/?$ /market.php last;
  rewrite ^/market/cart/?$ /market.php?view=cart last;
  rewrite ^/market/orders/?$ /market.php?view=orders last;
  rewrite ^/market/sales/?$ /market.php?view=sales last;
  rewrite ^/market/search/?$ /market.php?view=search last;
  rewrite ^/market/search/([^/]+)/?$ /market.php?view=search&query=$1 last;
  rewrite ^/market/search/([^/]+)/([^/]+)/?$ /market.php?view=search&query=$1&page=$2 last;
  rewrite ^/market/category/([^/]+)/?$ /market.php?view=category&category_id=$1 last;
  rewrite ^/market/category/([^/]+)/([^/]+)/?$ /market.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/market/category/([^/]+)/([^/]+)/([^/]+)/?$ /market.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/market/([^/]+)/?$ /market.php?page=$1 last;
  rewrite ^/my/funding/?$ /index.php?view=funding last;
  rewrite ^/funding/?$ /funding.php last;
  rewrite ^/funding/([^/]+)/([^/]+)/?$ /funding.php?view=funding_request&post_id=$1 last;
  rewrite ^/my/offers/?$ /index.php?view=offers last;
  rewrite ^/offers/?$ /offers.php last;
  rewrite ^/offers/search/?$ /offers.php?view=search last;
  rewrite ^/offers/search/([^/]+)/?$ /offers.php?view=search&query=$1 last;
  rewrite ^/offers/search/([^/]+)/([^/]+)/?$ /offers.php?view=search&query=$1&page=$2 last;
  rewrite ^/offers/category/([^/]+)/?$ /offers.php?view=category&category_id=$1 last;
  rewrite ^/offers/category/([^/]+)/([^/]+)/?$ /offers.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/offers/category/([^/]+)/([^/]+)/([^/]+)/?$ /offers.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/offers/([^/]+)/?$ /offers.php?page=$1 last;
  rewrite ^/my/jobs/?$ /index.php?view=jobs last;
  rewrite ^/jobs/?$ /jobs.php last;
  rewrite ^/jobs/search/?$ /jobs.php?view=search last;
  rewrite ^/jobs/search/([^/]+)/?$ /jobs.php?view=search&query=$1 last;
  rewrite ^/jobs/search/([^/]+)/([^/]+)/?$ /jobs.php?view=search&query=$1&page=$2 last;
  rewrite ^/jobs/category/([^/]+)/?$ /jobs.php?view=category&category_id=$1 last;
  rewrite ^/jobs/category/([^/]+)/([^/]+)/?$ /jobs.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/jobs/category/([^/]+)/([^/]+)/([^/]+)/?$ /jobs.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/jobs/([^/]+)/?$ /jobs.php?page=$1 last;
  rewrite ^/my/courses/?$ /index.php?view=courses last;
  rewrite ^/courses/?$ /courses.php last;
  rewrite ^/courses/search/?$ /courses.php?view=search last;
  rewrite ^/courses/search/([^/]+)/?$ /courses.php?view=search&query=$1 last;
  rewrite ^/courses/search/([^/]+)/([^/]+)/?$ /courses.php?view=search&query=$1&page=$2 last;
  rewrite ^/courses/category/([^/]+)/?$ /courses.php?view=category&category_id=$1 last;
  rewrite ^/courses/category/([^/]+)/([^/]+)/?$ /courses.php?view=category&category_id=$1&category_url=$2 last;
  rewrite ^/courses/category/([^/]+)/([^/]+)/([^/]+)/?$ /courses.php?view=category&category_id=$1&category_url=$2&page=$3 last;
  rewrite ^/courses/([^/]+)/?$ /courses.php?page=$1 last;
  rewrite ^/forums/?$ /forums.php last;
  rewrite ^/forums/my-threads/?$ /forums.php?view=my-threads last;
  rewrite ^/forums/my-replies/?$ /forums.php?view=my-replies last;
  rewrite ^/forums/search/?$ /forums.php?view=search last;
  rewrite ^/forums/search-results/?$ /forums.php?view=search-results last;
  rewrite ^/forums/new-thread/([^/]+)/?$ /forums.php?view=new-thread&forum_id=$1 last;
  rewrite ^/forums/edit-thread/([^/]+)/?$ /forums.php?view=edit-thread&thread_id=$1 last;
  rewrite ^/forums/new-reply/([^/]+)/?$ /forums.php?view=new-reply&thread_id=$1 last;
  rewrite ^/forums/edit-reply/([^/]+)/?$ /forums.php?view=edit-reply&reply_id=$1 last;
  rewrite ^/forums/thread/([^/]+)/([^/]+)/?$ /forums.php?view=thread&thread_id=$1 last;
  rewrite ^/forums/([^/]+)/([^/]+)/?$ /forums.php?view=forum&forum_id=$1 last;
  rewrite ^/movies/?$ /movies.php last;
  rewrite ^/movies/search/?$ /movies.php?view=search last;
  rewrite ^/movies/search/([^/]+)/?$ /movies.php?view=search&query=$1 last;
  rewrite ^/movies/search/([^/]+)/([^/]+)/?$ /movies.php?view=search&query=$1&page=$2 last;
  rewrite ^/movies/genre/([^/]+)/?$ /movies.php?view=genre&genre_id=$1 last;
  rewrite ^/movies/genre/([^/]+)/([^/]+)/?$ /movies.php?view=genre&genre_id=$1&genre_url=$2 last;
  rewrite ^/movies/genre/([^/]+)/([^/]+)/([^/]+)/?$ /movies.php?view=genre&genre_id=$1&genre_url=$2&page=$3 last;
  rewrite ^/movies/([^/]+)/?$ /movies.php?page=$1 last;
  rewrite ^/movie/([^/]+)/([^/]+)/?$ /movies.php?view=movie&movie_id=$1 last;
  rewrite ^/games/?$ /games.php last;
  rewrite ^/games/played/?$ /games.php?view=played last;
  rewrite ^/games/genre/([^/]+)/?$ /games.php?view=genre&genre_id=$1 last;
  rewrite ^/games/genre/([^/]+)/([^/]+)/?$ /games.php?view=genre&genre_id=$1&genre_url=$2 last;
  rewrite ^/games/genre/([^/]+)/([^/]+)/([^/]+)/?$ /games.php?view=genre&genre_id=$1&genre_url=$2&page=$3 last;
  rewrite ^/games/([^/]+)/([^/]+)/?$ /games.php?view=game&game_id=$1 last;
  rewrite ^/api/([^/]+)/?$ /api.php?do=$1 last;
  rewrite ^/developers/?$ /developers.php last;
  rewrite ^/developers/([^/]+)/?$ /developers.php?view=$1 last;
  rewrite ^/developers/edit/([^/]+)/?$ /developers.php?view=edit&app_auth_id=$1 last;
  rewrite ^/share/?$ /share.php last;
  rewrite ^/merits/?$ /merits.php last;
  rewrite ^/modcp/?$ /moderator.php last;
  rewrite ^/modcp/([^/]+)/?$ /moderator.php?view=$1 last;
  rewrite ^/modcp/([^/]+)/([^/]+)/?$ /moderator.php?view=$1&sub_view=$2 last;
  rewrite ^/modcp/([^/]+)/([^/]+)/([^/]+)/?$ /moderator.php?view=$1&sub_view=$2&id=$3 last;
  rewrite ^/admincp/?$ /admin.php last;
  rewrite ^/admincp/([^/]+)/?$ /admin.php?view=$1 last;
  rewrite ^/admincp/([^/]+)/([^/]+)/?$ /admin.php?view=$1&sub_view=$2 last;
  rewrite ^/admincp/([^/]+)/([^/]+)/([^/]+)/?$ /admin.php?view=$1&sub_view=$2&id=$3 last;
  rewrite ^/([^/]+)/?$ /profile.php?username=$1 last;
  rewrite ^/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2 last;
  rewrite ^/([^/]+)/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2&id=$3 last;
}