Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:nginx [2015/05/01 18:54] alfred [NGINX + PHP] |
wiki2:nginx [2022/03/12 11:02] (actual) |
||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== NGINX ====== | ====== NGINX ====== | ||
| + | |||
| + | ===== Basics ===== | ||
| + | |||
| + | Reload configuration inside docker: | ||
| + | |||
| + | <code> | ||
| + | docker exec -ti nginxcontainer nginx -s reload | ||
| + | </code> | ||
| + | |||
| + | ===== Example rules ===== | ||
| + | |||
| + | ==== Deny all requests that contain "wp-cron.php" anywhere ==== | ||
| + | <code> | ||
| + | location ~ wp-cron.php? { | ||
| + | deny all; | ||
| + | access_log off; | ||
| + | log_not_found off; | ||
| + | return 444; | ||
| + | } | ||
| + | </code> | ||
| + | ===== Enable sites ===== | ||
| + | <code> | ||
| + | $ ln -s /etc/nginx/sites-available/seximes /etc/nginx/sites-enabled/ | ||
| + | $ service nginx restart | ||
| + | </code> | ||
| ===== NGINX + PHP ===== | ===== NGINX + PHP ===== | ||
| Install the dependences: | Install the dependences: | ||
| Línea 37: | Línea 62: | ||
| To install mysql: ''sudo apt-get install mysql-server php5-mysql'' | To install mysql: ''sudo apt-get install mysql-server php5-mysql'' | ||
| + | ==== Note ==== | ||
| + | :?: At this point I do not know if this works for a 502 Bad Gateway error but... | ||
| + | <code> | ||
| + | fastcgi_buffer_size 128k; | ||
| + | fastcgi_buffers 8 128k; | ||
| + | fastcgi_busy_buffers_size 128k; | ||
| + | fastcgi_temp_file_write_size 128k; | ||
| + | </code> | ||
| + | |||
| + | ==== Example for php7 ==== | ||
| + | |||
| + | You have to ensure that php7 is working: | ||
| + | <code> | ||
| + | service --status-all | ||
| + | service php7.0-fpm status | ||
| + | </code> | ||
| + | |||
| + | You can put a ''check.php'' file on your site: | ||
| + | <code> | ||
| + | <?php phpinfo(); ?> | ||
| + | </code> | ||
| + | |||
| + | <code> | ||
| + | server { | ||
| + | server_name mantis.codi.coop; | ||
| + | root /srv/mantis; | ||
| + | |||
| + | location ~ \.php$ { | ||
| + | try_files $uri =404; | ||
| + | fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
| + | fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; | ||
| + | fastcgi_index index.php; | ||
| + | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| + | include fastcgi_params; | ||
| + | |||
| + | fastcgi_buffer_size 128k; | ||
| + | fastcgi_buffers 8 128k; | ||
| + | fastcgi_busy_buffers_size 128k; | ||
| + | fastcgi_temp_file_write_size 128k; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </code> | ||
| ===== Notes ===== | ===== Notes ===== | ||
| ==== With wordpress ==== | ==== With wordpress ==== | ||
| Línea 46: | Línea 114: | ||
| { | { | ||
| rewrite ^(.+)$ /index.php?q=$1 last; | rewrite ^(.+)$ /index.php?q=$1 last; | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | ==== Redirect to Flask app (in Gunicorn) ==== | ||
| + | <code> | ||
| + | server { | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | server_name alfred.is-a-rockstar.com; | ||
| + | location / { | ||
| + | proxy_pass http://127.0.0.1:5000; | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </code> | ||
| + | |||
| + | ==== Redirect www to another ==== | ||
| + | <code> | ||
| + | # /etc/nginx/sites-available/exploreflask.com | ||
| + | |||
| + | # Redirect www.exploreflask.com to exploreflask.com | ||
| + | server { | ||
| + | server_name www.exploreflask.com; | ||
| + | rewrite ^ http://exploreflask.com/ permanent; | ||
| + | } | ||
| + | |||
| + | # Handle requests to exploreflask.com on port 80 | ||
| + | server { | ||
| + | listen 80; | ||
| + | server_name exploreflask.com; | ||
| + | |||
| + | # Handle all locations | ||
| + | location / { | ||
| + | # Pass the request to Gunicorn | ||
| + | proxy_pass http://127.0.0.1:8000; | ||
| + | |||
| + | # Set some HTTP headers so that our app knows where the | ||
| + | # request really came from | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| + | } | ||
| + | } | ||
| + | </code> | ||
| + | ==== Having several hosts ==== | ||
| + | You can have several "server", for example: | ||
| + | <code> | ||
| + | server { | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | server_name alfred.is-a-rockstar.com; | ||
| + | location / { | ||
| + | proxy_pass http://127.0.0.1:5000; | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </code> | ||
| + | and | ||
| + | <code> | ||
| + | server { | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | |||
| + | root /var/www/seximes; | ||
| + | index index.html index.htm; | ||
| + | |||
| + | server_name seximes.cat; | ||
| + | |||
| + | location / { | ||
| + | try_files $uri $uri/ =404; | ||
| + | } | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | ==== Example reverse proxy configuration ==== | ||
| + | <code> | ||
| + | server { | ||
| + | server_name wiki.sir.gtd; | ||
| + | location / { | ||
| + | proxy_pass http://dokuwiki:80; | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header Accept-Encoding ""; | ||
| + | proxy_set_header X-Real-IP $remote_addr; | ||
| + | proxy_buffering off; | ||
| + | } | ||
| + | |||
| + | listen 80; | ||
| } | } | ||
| </code> | </code> | ||