Last active
February 27, 2019 12:09
-
-
Save pthiers/a282069803536c4fcefb to your computer and use it in GitHub Desktop.
Nginx: php and socket.io reverse proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name 192.168.0.1; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
root /srv/www/public_html; | |
index index.php; | |
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { | |
expires max; | |
log_not_found off; | |
} | |
location / { | |
# Check if a file or directory index file exists, else route it to index.php. | |
try_files $uri $uri/ /index.php; | |
} | |
location ~ ^/(node|socket\.io) { | |
proxy_pass http://localhost:3000; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_redirect off; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
location ~ \.php$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment