Nginx multiple access_log / multiple same server_name


Actually i have one site and two servers in Nginx conf file.

The first:

 server {
        listen   80 default;
        server_name  localhost;
        access_log off;
        rewrite ^ https://$http_host$request_uri? permanent;    # force redirect http to https

The second

server {
       listen   443 ssl;
       server_name  localhost;

       ssl  on;
       ssl_certificate  /etc/nginx/certificates/test.crt;
       ssl_certificate_key   /etc/nginx/certificates/test.key;
       access_log /home/collecte.log;
       root   /var/www;

       location / {
                index  index.php index.html index.htm;

        location ~ \.php$ {

                if ( $request ~* myString){
                         access_log off;
                        # access_log /home/collecte2.log;

                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
                include fastcgi_params;

        location ~* \.(ico|css|js|gif|jpg|jpeg|png)$ {
                expires 1d;
                add_header Pragma public;
                add_header Cache-Control "public";

The idea is to separate requests in two files. Like in the second server i disabled the log for same requests and i want to save them in another access_log file.

I tried access_log /home/collecte2.log; but it doesn’t work. Does anyone have any idea if i can duplicate the server with same configuration or with a different server name? How can i create two log files that receive a specific requests

Best regards, Nizar.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

After updating your configuration files did you restart your nginx service so the change could take effect? service nginx restart