Crmgo Blog

Nginx auf CentOS

Nginx auf CentOS

yum install nginx Jetzt konfigurieren wir Apache neu. Dazu öffnen wir etc/httpd/conf/httpd.conf und ändern dort NameVirtualHost in: NameVirtualHost 127.0.0.1:8080. Ebenso ändern wir das öffnende Tag jedes virtuellen Hosts: <VirtualHost 127.0.0.1:8080>. Mit Apache ist das im Prinzip erledigt. Wir wechseln nach /etc/nginx und öffnen nginx.conf. Und so,…

Nginx auf CentOS
yum install nginx

Jetzt konfigurieren wir Apache neu. Dazu öffnen wir etc/httpd/conf/httpd.conf und ändern NameVirtualHost in:

NameVirtualHost 127.0.0.1:8080

Ändern Sie außerdem das öffnende Tag jedes virtuellen Hosts:

<VirtualHost 127.0.0.1:8080>

Im Prinzip ist mit Apache alles erledigt. Wechseln Sie nach /etc/nginx und öffnen Sie nginx.conf. Hier sind die allgemeinen Parameter:

user nginx; worker_processes 4; error_log /var/log/nginx/error.log debug; pid /var/run/nginx.pid;
events { worker_connections 1024; }

Parameter des HTTP-Servers:

http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; #Inhalt komprimieren gzip on; gzip_min_length 1100; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/xml application/x-javascript text/javascript text/css; gzip_disable "msie6"; gzip_disable Firefox/([0-2]\.|3\.0); gzip_disable Chrome/2; gzip_disable Safari; gzip_comp_level 3;

Und nun muss für jeden virtuellen Host folgender Eintrag vorhanden sein:

server { listen 80; server_name eddnet.org www.eddnet.org; access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 10m; }

Wenn Sie bestimmte Inhalte zwischenspeichern (cachen) möchten, fügen Sie einfach folgende Beschreibung hinzu:

location /uploads/files { add_header Content-type application/octet-stream; internal; } location /uploads/img { #Bilder für einen Monat zwischenspeichern expires 4M; #Zwischenspeicherung überall aktivieren (sowohl beim Proxy als auch bei den Clients) add_header Cache-Control public; } location /cache/tumb/ { #Bilder für einen Monat zwischenspeichern expires 4M; #Zwischenspeicherung überall aktivieren (sowohl beim Proxy als auch bei den Clients) add_header Cache-Control public; }

Hier ist die vollständige Konfiguration, damit Sie nicht verwirrt sind, was wo und wie gehört:

user nginx; worker_processes 4; error_log /var/log/nginx/error.log debug; pid /var/run/nginx.pid; events { worker_connections 1024; } ## Timeouts http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; gzip on; gzip_min_length 1100; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain application/xml application/x-javascript text/javascript text/css; gzip_disable "msie6"; gzip_disable Firefox/([0-2]\.|3\.0); gzip_disable Chrome/2; gzip_disable Safari; gzip_comp_level 3; server { listen 80; server_name eddnet.org www.eddnet.org; access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 10m; } } server { listen 80; server_name wot-news.com www.wot-news.com; access_log /var/log/nginx/host.access.log main; root /var/www/vhosts/wot-news.com/http; expires epoch; location / { proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 10m; } location /uploads/files { add_header Content-type application/octet-stream; internal; } location /uploads/img { #Bilder des Monats für 4 Monate cachen expires 4M; #Caching überall aktivieren (sowohl für Proxies als auch für Clients) add_header Cache-Control public; } location /cache/tumb/ { #Bilder des Monats für 4 Monate cachen expires 4M; #Caching überall aktivieren (sowohl für Proxies als auch für Clients) add_header Cache-Control public; } } }

Hinweis: Dieser Beitrag kann KI-unterstützt erstellt und anschließend redaktionell geprüft worden sein. Verantwortlich: Dmytro Lomaka, Kaltenkirchen.