Skip to main content
Code Review

Return to Question

update wording
Source Link

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's confconfiguration.

While this combination works and the sites appears fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given that my code seems to be a bit repetitive, I want to ask: Can it be made a bit less repetitive?

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's conf.

While this combination works and the sites appears fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given that my code seems to be a bit repetitive, I want to ask: Can it be made a bit less repetitive?

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's configuration.

While this combination works and the sites appears fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given that my code seems to be a bit repetitive, I want to ask: Can it be made a bit less repetitive?

added 6 characters in body
Source Link

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's conf.

While this combination works and the sites appearappears fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given that my code seems to mebe a bit repetitive, I want to ask: Can it be made a bit less repetitive?

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's conf.

While this combination works and the sites appear fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given my code seems to me a bit repetitive, I want to ask: Can it be made a bit less repetitive?

The following code is an Nginx default conf file. The conf file itself includes another server block which holds a site's conf.

While this combination works and the sites appears fine on web, I have a feeling that my code doesn't follow the DRY standard.

server {
 server_name _;
 return 301 https://$host$request_uri;
 root /var/www/html;
 index index.php index.html index.htm;
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location / {
 try_files $uri $uri/ =404;
 }
 location ~ /\.ht {
 deny all;
 }
 # notes {
 # 443 ssl http2;
 # [::]:443 ssl http2;
 # }
}
server {
 listen 80;
 listen [::]:80;
 server_name contfix.co.il www.contfix.co.il;
 ssl_certificate /etc/nginx/conf.d/ssl/contfix.co.il.crt;
 ssl_certificate_key /etc/nginx/conf.d/ssl/contfix.co.il.key;
 ssl_dhparam /etc/nginx/conf.d/ssl/dhparam.pem;
 root /var/www/html/contfix.co.il;
 location / {
 index index.php index.html index.htm;
 try_files $uri $uri/ /index.php?$args;
 }
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass 127.0.0.1:9000;
 }
 location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
 expires 365d;
 }
 location ~* \.(pdf)$ {
 expires 30d;
 }
}

Given that my code seems to be a bit repetitive, I want to ask: Can it be made a bit less repetitive?

Notice removed Canonical answer required by user125391
Bounty Ended with Sᴀᴍ Onᴇᴌᴀ's answer chosen by Community Bot
edited tags
Link
Tweeted twitter.com/StackCodeReview/status/1200384056384512001
Notice added Canonical answer required by user125391
Bounty Started worth 50 reputation by Community Bot
deleted 3 characters in body; edited title
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
Loading
Source Link
user125391
user125391
Loading
default

AltStyle によって変換されたページ (->オリジナル) /