Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to run apache and nginx on same machine. I configured apache and running fine on port 80. Now I want to configure nginx on port 7007. I did changes in nginx.conf. Here is the nginx.conf file-

user nginx root;
worker_processes  3;
worker_rlimit_nofile 200000;


error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  65535;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
        index index.php index.htm index.html;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;
    access_log off;

    sendfile        on;
    tcp_nopush      on;
   tcp_nodelay     on;
    server_tokens   off;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  80 15;
  #  limit_conn_zone   $binary_remote_addr  zone=addr:10m;


    include /etc/nginx/conf.d/*.conf;

    server {
#        limit_conn addr 20000;

        listen       7007;
        server_name  _;




            root   /usr/share/nginx/html;
        location / {


        }

        error_page  404              /404.html;

        location = /404.html {
  }
        location /favicon.ico {
            empty_gif;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {

        }

 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_connect_timeout 8m;
            fastcgi_send_timeout  8m;
        }

#        location ~ \.php$ {
#            root           /usr/share/nginx/html;
            #fastcgi_pass   localhost:9000;
#            fastcgi_pass   unix:/tmp/php.sock;
#            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #include        fastcgi_params;
#           fastcgi_send_timeout  8m;

#           fastcgi_connect_timeout 8m;
            #uwsgi_pass_request_body off;
#           include /etc/nginx/fastcgi.conf;
 #       }

        location /status {
                stub_status on;
                access_log   off;
        #       allow ;
        #        allow 127.0.0.1;
        #        deny all;
        }

    }

}

When I start Nginx it shows Job failed. Here is the log.

Mar  7 15:55:12 localhost nginx[10973]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar  7 15:55:12 localhost nginx[10973]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar  7 15:55:12 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:12 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:13 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:13 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:14 localhost nginx[10975]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Mar  7 15:55:14 localhost nginx[10975]: nginx: [emerg] still could not bind()
Mar  7 15:55:14 localhost systemd[1]: nginx.service: control process exited, code=exited status=1
Mar  7 15:55:14 localhost systemd[1]: Unit nginx.service entered failed state.

Why it still going for port 80 ?

share|improve this question
    
Check /etc/nginx/conf.d to make sure there are no config files in there with conflicting directives. –  Flup Mar 7 '13 at 10:51
    
yes there was a default.conf file in conf.d folder which was restricting. Now nginx has installed on 7007 port but new problem arises. Php fastcgi is not working. When I installed nginx on port 80 after removing apache, fastcgi works properly. do you have any idea why it is so ? –  Himanshu Matta Mar 7 '13 at 11:26
add comment

1 Answer

up vote 0 down vote accepted

1) Make sure that you have no config file using port 80 in /etc/nginx/sites-enabled

2) Try to stop then start Nginx rather that restart it. Restart can be a problem with changing ports, sometimes.

share|improve this answer
    
you are right.. there was a default.conf file in conf.d folder which was restricting. Now nginx has installed on 7007 port but new problem arises. Php fastcgi is not working. When I installed nginx on port 80 after removing apache, fastcgi works properly. do you have any idea why it is so ? –  Himanshu Matta Mar 7 '13 at 11:27
    
Now I am no more able to run php on apache. Before nginx installation php was running well but after nginx installatino apache showing php code. –  Himanshu Matta Mar 7 '13 at 11:52
    
Are you sure PHP FPM is running on 127.0.0.1:9000 ? You should check PHP FPM config (default is /etc/php5/fpm/pool.d/www.conf on Debian). The new default way to connect Nginx with PHP FPM is a UNIX socket. Try to set fastcgi_pass unix:/var/run/php5-fpm.sock; instead of fastcgi_pass 127.0.0.1:9000; –  Godefroy Mar 7 '13 at 13:10
    
when I run this command.. netstat -tulpn | grep :9000 it shows {tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3565/php-cgi } it means phpcgi is running. –  Himanshu Matta Mar 7 '13 at 13:24
    
Ok. What errors do you get? Have checked the logs? (/var/log/php5-fpm.log and /var/log/nginx/error.log) If my answer helped you, don't forget to upvote it ;-) –  Godefroy Mar 7 '13 at 17:05
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.